赞
踩
将下面代码加入模板的functions.php文件
再到后台Coupons 添加 100off,200off的折扣码
function ts_apply_discount_to_cart() {
$order_total = WC()->cart->get_subtotal();
if( $order_total > 100 and $order_total < 200 ) {
$coupon_code = '100off';
if ( !WC()->cart->apply_coupon( sanitize_text_field( $coupon_code ) ) ) {
wc_print_notices();
}
}elseif ( $order_total > 200 ) {
$coupon_code = '200off';
if ( !WC()->cart->apply_coupon( sanitize_text_field( $coupon_code ) ) ) {
wc_print_notices();
}
}
}
add_action( 'woocommerce_before_cart_table', 'ts_apply_discount_to_cart' );
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。