woocommerce订单满减(订单达到多少应用优惠券)

下方代码,当订单金额到达50时,应用一张优惠券:

/**
* Apply a coupon for minimum cart total
*/

add_action( 'woocommerce_before_cart' , 'add_coupon_notice' );
add_action( 'woocommerce_before_checkout_form' , 'add_coupon_notice' );

function add_coupon_notice() {

        $cart_total = WC()->cart->get_subtotal();
        $minimum_amount = 50;
        $currency_code = get_woocommerce_currency();//货币符号
        wc_clear_notices();

       if ( $cart_total < $minimum_amount ) {
              WC()->cart->remove_coupon( 'urmwz5d9' );
              wc_print_notice( "Get 50% off if you spend more than $minimum_amount $currency_code!", 'notice' );
        } else {
              WC()->cart->apply_coupon( 'urmwz5d9' );
              wc_print_notice( 'You just got 50% off your order!', 'notice' );
        }
          wc_clear_notices();
}
© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享