-
-
Save KoolPal/f50b9f92482991e9b7ff8cff52cdeccc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
rs::metabox(array( | |
'title' => 'Select custom date sale', | |
'layout' => 'none', | |
'rules' => array( | |
'post_type' => 'product' | |
), | |
'context' => 'normal', | |
'priority' => 'default', | |
'controls' => array( | |
array( | |
'name' => 'product_price', | |
'label'=> 'Giá sản phẩm', | |
'type' => 'text', | |
), | |
array( | |
'name' => 'kieu_giam_gia', | |
'label'=> 'Giảm giá theo', | |
'type' => 'radio', | |
'items' => array('phan_tram' => __('Phần trăm','woocommerce'), 'co_dinh' => 'Cố định' ), | |
), | |
array( | |
'name' => 'ngay_chan', | |
'label'=> 'Ngày chẵn', | |
'type' => 'text', | |
), | |
array( | |
'name' => 'ngay_le', | |
'label'=> 'Ngày lẻ', | |
'type' => 'text', | |
), | |
) | |
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shipping Methods Display | |
* | |
* In 2.1 we show methods per package. This allows for multiple methods per order if so desired. | |
* | |
* @author WooThemes | |
* @package WooCommerce/Templates | |
* @version 2.3.0 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
?> | |
<tr class="shipping"> | |
<th><?php | |
if ( $show_package_details ) { | |
printf( __( 'Shipping #%d', 'woocommerce' ), $index + 1 ); | |
} else { | |
_e( 'Shipping', 'woocommerce' ); | |
} | |
?></th> | |
<th> | |
</th> | |
<td> | |
<?php if ( ! empty( $available_methods ) ) : ?> | |
<?php if ( 1 === count( $available_methods ) ) : | |
$method = current( $available_methods ); | |
echo wp_kses_post( wc_cart_totals_shipping_method_label( $method ) ); ?> | |
<input type="hidden" name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>" value="<?php echo esc_attr( $method->id ); ?>" class="shipping_method" /> | |
<?php elseif ( get_option( 'woocommerce_shipping_method_format' ) === 'select' ) : ?> | |
<select name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>" class="shipping_method"> | |
<?php foreach ( $available_methods as $method ) : ?> | |
<option value="<?php echo esc_attr( $method->id ); ?>" <?php selected( $method->id, $chosen_method ); ?>><?php echo wp_kses_post( wc_cart_totals_shipping_method_label( $method ) ); ?></option> | |
<?php endforeach; ?> | |
</select> | |
<?php else : ?> | |
<ul id="shipping_method"> | |
<?php foreach ( $available_methods as $method ) : ?> | |
<li> | |
<input type="radio" name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>" value="<?php echo esc_attr( $method->id ); ?>" <?php checked( $method->id, $chosen_method ); ?> class="shipping_method" /> | |
<label for="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>"><?php echo wp_kses_post( wc_cart_totals_shipping_method_label( $method ) ); ?></label> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
<?php endif; ?> | |
<?php elseif ( ! WC()->customer->get_shipping_state() || ! WC()->customer->get_shipping_postcode() ) : ?> | |
<?php if ( is_cart() && get_option( 'woocommerce_enable_shipping_calc' ) === 'yes' ) : ?> | |
<p><?php _e( 'Please use the shipping calculator to see available shipping methods.', 'woocommerce' ); ?></p> | |
<?php elseif ( is_cart() ) : ?> | |
<p><?php _e( 'Please continue to the checkout and enter your full address to see if there are any available shipping methods.', 'woocommerce' ); ?></p> | |
<?php else : ?> | |
<p><?php _e( 'Please fill in your details to see available shipping methods.', 'woocommerce' ); ?></p> | |
<?php endif; ?> | |
<?php else : ?> | |
<?php if ( is_cart() ) : ?> | |
<?php echo apply_filters( 'woocommerce_cart_no_shipping_available_html', | |
'<p>' . __( 'There are no shipping methods available. Please double check your address, or contact us if you need any help.', 'woocommerce' ) . '</p>' | |
); ?> | |
<?php else : ?> | |
<?php echo apply_filters( 'woocommerce_no_shipping_available_html', | |
'<p>' . __( 'There are no shipping methods available. Please double check your address, or contact us if you need any help.', 'woocommerce' ) . '</p>' | |
); ?> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php if ( $show_package_details ) : ?> | |
<?php | |
foreach ( $package['contents'] as $item_id => $values ) { | |
if ( $values['data']->needs_shipping() ) { | |
$product_names[] = $values['data']->get_title() . ' ×' . $values['quantity']; | |
} | |
} | |
echo '<p class="woocommerce-shipping-contents"><small>' . __( 'Shipping', 'woocommerce' ) . ': ' . implode( ', ', $product_names ) . '</small></p>'; | |
?> | |
<?php endif; ?> | |
<?php if ( is_cart() ) : ?> | |
<?php woocommerce_shipping_calculator(); ?> | |
<?php endif; ?> | |
</td> | |
</tr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cart Page | |
* | |
* @author WooThemes | |
* @package WooCommerce/Templates | |
* @version 2.3.8 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly | |
} | |
wc_print_notices(); | |
do_action( 'woocommerce_before_cart' ); ?> | |
<form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post"> | |
<?php do_action( 'woocommerce_before_cart_table' ); ?> | |
<table class="shop_table cart" cellspacing="0"> | |
<thead> | |
<tr> | |
<th class="product-remove"> </th> | |
<th class="product-thumbnail"><?php _e( ' Hình ảnh', 'woocommerce' ); ?></th> | |
<th class="product-name"><?php _e( 'Sản phẩm', 'woocommerce' ); ?></th> | |
<th class="product-price"><?php _e( 'Giá', 'woocommerce' ); ?></th> | |
<th class="product-quantity"><?php _e( 'Ngày chọn', 'woocommerce' ); ?></th> | |
<th class="product-subtotal"><?php _e( 'Tổng tiền', 'woocommerce' ); ?></th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php do_action( 'woocommerce_before_cart_contents' ); ?> | |
<?php | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); | |
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) { | |
?> | |
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> | |
<td class="product-remove"> | |
<?php | |
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<a href="%s" class="remove" title="%s">×</a>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'woocommerce' ) ), $cart_item_key ); | |
?> | |
</td> | |
<td class="product-thumbnail"> | |
<?php | |
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); | |
if ( ! $_product->is_visible() ) | |
echo $thumbnail; | |
else | |
printf( '<a href="%s">%s</a>', $_product->get_permalink( $cart_item ), $thumbnail ); | |
?> | |
</td> | |
<td class="product-name"> | |
<?php | |
if ( ! $_product->is_visible() ) | |
echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . ' '; | |
else | |
echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s </a>', $_product->get_permalink( $cart_item ), $_product->get_title() ), $cart_item, $cart_item_key ); | |
// Meta data | |
echo WC()->cart->get_item_data( $cart_item ); | |
// Backorder notification | |
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) | |
echo '<p class="backorder_notification">' . __( 'Available on backorder', 'woocommerce' ) . '</p>'; | |
?> | |
</td> | |
<td class="product-price"> | |
<?php | |
echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); | |
?> | |
</td> | |
<td class="product-quantity"> | |
<?php | |
echo esc_attr($cart_item["select_date"]); | |
?> | |
</td> | |
<td class="product-subtotal"> | |
<?php | |
echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); | |
?> | |
</td> | |
</tr> | |
<?php | |
} | |
} | |
do_action( 'woocommerce_cart_contents' ); | |
?> | |
<tr> | |
<td colspan="6" class="actions"> | |
<?php if ( WC()->cart->coupons_enabled() ) { ?> | |
<div class="coupon"> | |
<label for="coupon_code"><?php _e( 'Coupon', 'woocommerce' ); ?>:</label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php _e( 'Coupon code', 'woocommerce' ); ?>" /> <input type="submit" class="button" name="apply_coupon" value="<?php _e( 'Apply Coupon', 'woocommerce' ); ?>" /> | |
<?php do_action( 'woocommerce_cart_coupon' ); ?> | |
</div> | |
<?php } ?> | |
<input type="submit" class="button" name="update_cart" value="<?php _e( 'Update Cart', 'woocommerce' ); ?>" /> | |
<?php do_action( 'woocommerce_cart_actions' ); ?> | |
<?php wp_nonce_field( 'woocommerce-cart' ); ?> | |
</td> | |
</tr> | |
<?php do_action( 'woocommerce_after_cart_contents' ); ?> | |
</tbody> | |
</table> | |
<?php do_action( 'woocommerce_after_cart_table' ); ?> | |
</form> | |
<div class="cart-collaterals"> | |
<?php do_action( 'woocommerce_cart_collaterals' ); ?> | |
</div> | |
<?php do_action( 'woocommerce_after_cart' ); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Review order table | |
* | |
* @author WooThemes | |
* @package WooCommerce/Templates | |
* @version 2.3.0 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
?> | |
<table class="shop_table woocommerce-checkout-review-order-table"> | |
<thead> | |
<tr> | |
<th class="product-name"><?php _e( 'Sản phẩm', 'woocommerce' ); ?></th> | |
<th class="product-total"><?php _e( 'Ngày chọn', 'woocommerce' ); ?></th> | |
<th class="product-total"><?php _e( 'Tổng cộng', 'woocommerce' ); ?></th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
do_action( 'woocommerce_review_order_before_cart_contents' ); | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) { | |
?> | |
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> | |
<td class="product-name"> | |
<?php echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . ' '; ?> | |
<?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( '× %s', $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); ?> | |
<?php echo WC()->cart->get_item_data( $cart_item ); ?> | |
</td> | |
<td class="product-total"> | |
<?php echo esc_attr($cart_item["select_date"]); ?> | |
</td> | |
<td class="product-total"> | |
<?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); ?> | |
</td> | |
</tr> | |
<?php | |
} | |
} | |
do_action( 'woocommerce_review_order_after_cart_contents' ); | |
?> | |
</tbody> | |
<tfoot> | |
<tr class="cart-subtotal"> | |
<th><?php _e( 'Subtotal', 'woocommerce' ); ?></th> | |
<th><?php _e( '', 'woocommerce' ); ?></th> | |
<td><?php wc_cart_totals_subtotal_html(); ?></td> | |
</tr> | |
<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?> | |
<tr class="cart-discount coupon-<?php echo esc_attr( $code ); ?>"> | |
<th><?php wc_cart_totals_coupon_label( $coupon ); ?></th> | |
<th></th> | |
<td><?php wc_cart_totals_coupon_html( $coupon ); ?></td> | |
</tr> | |
<?php endforeach; ?> | |
<?php if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) : ?> | |
<?php do_action( 'woocommerce_review_order_before_shipping' ); ?> | |
<?php wc_cart_totals_shipping_html(); ?> | |
<?php do_action( 'woocommerce_review_order_after_shipping' ); ?> | |
<?php endif; ?> | |
<?php foreach ( WC()->cart->get_fees() as $fee ) : ?> | |
<tr class="fee"> | |
<th><?php echo esc_html( $fee->name ); ?></th> | |
<td><?php wc_cart_totals_fee_html( $fee ); ?></td> | |
</tr> | |
<?php endforeach; ?> | |
<?php if ( WC()->cart->tax_display_cart === 'excl' ) : ?> | |
<?php if ( get_option( 'woocommerce_tax_total_display' ) === 'itemized' ) : ?> | |
<?php foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : ?> | |
<tr class="tax-rate tax-rate-<?php echo sanitize_title( $code ); ?>"> | |
<th><?php echo esc_html( $tax->label ); ?></th> | |
<td><?php echo wp_kses_post( $tax->formatted_amount ); ?></td> | |
</tr> | |
<?php endforeach; ?> | |
<?php else : ?> | |
<tr class="tax-total"> | |
<th><?php echo esc_html( WC()->countries->tax_or_vat() ); ?></th> | |
<td><?php echo wc_price( WC()->cart->get_taxes_total() ); ?></td> | |
</tr> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php do_action( 'woocommerce_review_order_before_order_total' ); ?> | |
<tr class="order-total"> | |
<th><?php _e( 'Total', 'woocommerce' ); ?></th> | |
<th><?php _e( '', 'woocommerce' ); ?></th> | |
<td><?php wc_cart_totals_order_total_html(); ?></td> | |
</tr> | |
<?php do_action( 'woocommerce_review_order_after_order_total' ); ?> | |
</tfoot> | |
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The template for displaying all single posts. | |
* | |
* @package rst | |
*/ | |
global $post, $product, $woocommerce, $simple_no_parent; | |
get_header(); | |
the_post(); | |
?> | |
<?php | |
// parse_product($product); | |
?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($){ | |
var product_price = '<?php echo wc_price($product->product_price); ?>'; | |
var sale_price_ngay_chan = '<?php echo wc_price($product->sale_price_ngay_chan); ?>'; | |
var sale_price_ngay_le = '<?php echo wc_price($product->sale_price_ngay_le); ?>'; | |
$('#select_date').live('click',function(){ | |
if(parseInt($(this).val()) % 2 == 0){ | |
$('#lbltotalbottom').html(sale_price_ngay_chan); | |
} | |
else{ | |
$('#lbltotalbottom').html(sale_price_ngay_le); | |
} | |
}); | |
}); | |
</script> | |
<?php if( rs::getField('rst_show_title') ) { ?> | |
<div class="text-center" id="tf-page-header"> | |
<div class="container"> | |
<?php if( rs::getField('rst_sub_title') ) { ?> | |
<h5><em><?php echo rs::getField('rst_sub_title') ?></em></h5> | |
<hr> | |
<?php } ?> | |
<h2 class="text-uppercase"><?php the_title() ?></h2> | |
</div> | |
</div> | |
<?php } ?> | |
<?php | |
//var_dump($product); | |
?> | |
<!--- Content --> | |
<div id="tf-content"> | |
<div class="container"><!-- Container --> | |
<div class="row"><!-- Row --> | |
<?php | |
do_action( 'woocommerce_before_add_to_cart_form' ); | |
?> | |
<form class="cart" method="post" enctype='multipart/form-data'> | |
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" /> | |
<input type="hidden" name="tour_date" value="" id="tour_date"/> | |
<div id="booktour"> | |
<!-- Booking Widget --> | |
<div id="jumptobooking" class="booking-block"> | |
<div class="inner2"> | |
<h3>Thông tin</h3> | |
<div class="inner-inner"> | |
<h4><span>4.</span> Optionals:</h4> | |
<div class="container-checkbox"> | |
<div class="caption-optional">Select date</div> | |
<select name="select_date" id="select_date"> | |
<option value="">Chọn ngày</option> | |
<option value="1">1</option> | |
<option value="2">2</option> | |
<option value="3">3</option> | |
<option value="4">4</option> | |
<option value="5">5</option> | |
<option value="6">6</option> | |
<option value="7">7</option> | |
<option value="8">8</option> | |
<option value="9">9</option> | |
<option value="10">10</option> | |
<option value="11">11</option> | |
<option value="12">12</option> | |
</select> | |
</div> | |
<!-- /optional --> | |
<hr /> | |
<!-- If On Sale Disply Orginal Total --> | |
<div class="row sales-row"> | |
<div class="col-md-6"> | |
<p> | |
</p> | |
</div> | |
<div class="col-md-6 text-right"> | |
<p> | |
<span></span> | |
</p> | |
</div> | |
</div> | |
<!-- End of Orginal Total --> | |
<div class="row totals-row" id="tot-amount"> | |
<div class="col-md-4"> | |
<p> | |
Total | |
</p> | |
</div> | |
<div class="col-md-8 text-right"> | |
<p> | |
<span class="priceSign"><?php //echo get_woocommerce_currency_symbol() ?></span><span id="lbltotalbottom"><?php echo wc_price(00.00);?></span> | |
</p> | |
</div> | |
</div> | |
<button class="addtocart-button" id="book_button"> | |
<span class="primary">Add to Cart</span><br /> | |
</button> | |
<?php do_action( 'woocommerce_product_meta_end' ); ?> | |
</div> | |
</div> | |
</div> | |
</div> | |
</form> | |
<?php | |
global $rst_blog, $wp_query; | |
$template = rs::getField('rst_template_style') != 0 ? rs::getField('rst_template_style') : ( get_theme_mod('rst_page_layout') ? get_theme_mod('rst_page_layout') : 1 ); | |
$class = 'col-md-10 col-md-offset-1'; | |
$has_sidebar = $template == 2 || $template == 3; | |
if( $has_sidebar ) { | |
$class = 'col-md-8'; | |
} | |
?> | |
<?php if( $template == 2 ) { ?> | |
<div class="col-md-4"><?php get_sidebar() ?></div> | |
<?php } ?> | |
<div class="<?php echo esc_attr($class) ?>"> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<?php get_template_part( 'content', 'page' ); ?> | |
<?php endwhile; // end of the loop. ?> | |
<?php rst_the_posts_navigation(); ?> | |
</div> | |
<?php if( $template == 3 ) { ?> | |
<div class="col-md-4"><?php get_sidebar() ?></div> | |
<?php } ?> | |
</div><!-- .row --> | |
</div><!-- .container --> | |
</div><!-- #content --> | |
<?php get_footer(); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function parse_product($product){ | |
if(is_object($product)){ | |
global $woocommerce; | |
// var_dump($product); | |
$settings = get_option('_wcml_settings'); | |
$currency_options = $settings['currency_options']; | |
$currency = $woocommerce->session && $woocommerce->session->get('client_currency') ? $woocommerce->session->get('client_currency') : get_woocommerce_currency(); | |
$default_currency = get_option('woocommerce_currency'); | |
$product_id = ($product->id); | |
$product->product_price = rs::getField('product_price',$product_id); | |
$product->regular_price = rs::getField('product_price',$product_id); | |
$product->sale_price = $product->regular_price; | |
$product->kieu_giam_gia = rs::getField('kieu_giam_gia',$product_id); | |
$product->ngay_chan = (int) rs::getField('ngay_chan',$product_id); | |
$product->ngay_le = (int) rs::getField('ngay_le',$product_id); | |
if($product->kieu_giam_gia == 'phan_tram'){ | |
$product->sale_price_ngay_chan = $product->product_price - (($product->product_price/100)*$product->ngay_chan); | |
$product->sale_price_ngay_le = $product->product_price - (($product->product_price/100)*$product->ngay_le); | |
} | |
else{ | |
$product->sale_price_ngay_chan = $product->product_price - $product->ngay_chan; | |
$product->sale_price_ngay_le = $product->product_price - $product->ngay_le; | |
} | |
//add to is parsed | |
$product->parsed = true; | |
} | |
return $product; | |
} | |
// remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); | |
add_filter('the_post', 'update_product_attributes', 100); | |
function update_product_attributes(){ | |
global $product, $post; | |
if(is_object($product) && $post->ID == $product->id && !$product->parsed){ | |
$product = parse_product($product); | |
} | |
} | |
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_custom_data_vase', 10, 2 ); | |
function add_cart_item_custom_data_vase( $item, $product_id ) { | |
global $woocommerce; | |
$item['select_date'] = $_POST['select_date']; | |
return $item; | |
} | |
//Get it from the session and add it to the cart variable | |
function get_cart_items_from_session( $item, $values, $key ) { | |
$item['select_date'] = isset($values['select_date']) ? $values['select_date'] : ''; | |
$product = $item['data']; | |
if(is_object($product) && !$product->parsed){ | |
$product = parse_product($product); | |
} | |
if($item['select_date'] % 2 == 0){ | |
$total = $product->kieu_giam_gia == NULL ? $product->price : $product->sale_price_ngay_chan; | |
} | |
else{ | |
$total = $product->kieu_giam_gia == NULL ? $product->price : $product->sale_price_ngay_le; | |
} | |
$item['data']->set_price($total); | |
$item['data']->is_cart_product = true; | |
$item['cart_item_key'] = $key; | |
return $item; | |
} | |
add_filter( 'woocommerce_get_cart_item_from_session', 'get_cart_items_from_session', 11, 3 ); | |
add_action('woocommerce_add_order_item_meta', 'order_item_meta', 10, 2); | |
function order_item_meta($item_id, $item) { | |
if ( isset( $item['select_date'] ) ) | |
woocommerce_add_order_item_meta( $item_id, 'Select date', (int)$item['select_date'] ); | |
} | |
// add to check out and cart | |
// add_filter('woocommerce_checkout_cart_item_quantity','wdm_add_user_custom_option_from_session_into_cart',1,3); | |
// add_filter('woocommerce_cart_item_price','wdm_add_user_custom_option_from_session_into_cart',1,3); | |
// if(!function_exists('wdm_add_user_custom_option_from_session_into_cart')) | |
{ | |
function wdm_add_user_custom_option_from_session_into_cart($product_name, $values, $cart_item_key ) | |
{ | |
/*code to add custom data on Cart & checkout Page*/ | |
if(count($values['select_date']) > 0 || 1) | |
{ | |
$return_string = $product_name . "</a><dl class='variation'>"; | |
$return_string .= "<table class='wdm_options_table' id='" . $values['product_id'] . "'>"; | |
$return_string .= "<tr><td>" . $values['select_date'] . "after date</td></tr>"; | |
$return_string .= "</table></dl>"; | |
return $return_string; | |
} | |
else | |
{ | |
return $product_name; | |
} | |
} | |
} | |
add_filter('wc_cart_totals_shipping_html','wc_cart_totals_shipping_html_filter'); | |
function wc_cart_totals_shipping_html_filter() { | |
$packages = WC()->shipping->get_packages(); | |
foreach ( $packages as $i => $package ) { | |
$chosen_method = isset( WC()->session->chosen_shipping_methods[ $i ] ) ? WC()->session->chosen_shipping_methods[ $i ] : ''; | |
wc_get_template( 'cart/cart-shipping.php', array( 'package' => $package, 'available_methods' => $package['rates'], 'show_package_details' => ( sizeof( $packages ) > 1 ), 'index' => $i, 'chosen_method' => $chosen_method ) ); | |
} | |
} | |
// //change calculated total price in cart and checkout | |
add_action('woocommerce_cart_totals_after_order_total', 'cart_totals_after_order_total'); | |
add_action('woocommerce_review_order_after_order_total', 'cart_totals_after_order_total'); | |
function cart_totals_after_order_total(){ | |
$cart = WC()->cart; | |
?> | |
<tr class="order-paid"> | |
<th>Paid Today</th> | |
<th></th> | |
<td><?php echo wc_price($cart->total) ?></td> | |
</tr> | |
<?php | |
} | |
add_action('woocommerce_admin_order_item_headers', 'admin_order_item_headers'); | |
function admin_order_item_headers() | |
{ | |
?> | |
<th class="select_date"><?php _e('Day', 'woocommerce-select_date'); ?></th> | |
<?php | |
} | |
add_action('woocommerce_admin_order_item_values', 'admin_order_item_values', 10, 3); | |
function admin_order_item_values($product, $item, $item_id) | |
{ | |
global $post; | |
$order = $post ? wc_get_order($post->ID) : null; | |
$date = ''; | |
if(isset($item['Select date'])){ | |
$date = $item['Select date']; | |
} | |
?> | |
<td class="select_date" width="1%"> | |
<div class="view"> | |
<?php | |
echo ($date); | |
?> | |
</div> | |
<?php if ($product) { ?> | |
<div class="edit" style="display: none;"> | |
<input type="text" name="select_date[<?php echo absint($item_id); ?>]" value="<?php echo $date; ?>" class="select_date wc_input_price" data-date="<?php echo $date; ?>" /> | |
</div> | |
<?php } ?> | |
</td> | |
<?php | |
} | |
function custom_woocommerce_is_purchasable( $purchasable, $product ){ | |
if( $product->get_price() == 0 || $product->get_price() == '') | |
$purchasable = true; | |
return $purchasable; | |
} | |
add_filter( 'woocommerce_is_purchasable', 'custom_woocommerce_is_purchasable', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment