Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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 = 15;
- $currency_code = get_woocommerce_currency();
- wc_clear_notices();
- if ( $cart_total < $minimum_amount ) {
- WC()->cart->remove_coupon( '5% OFF' );
- wc_print_notice( "Get 5% off if you spend more than $minimum_amount $currency_code!", 'notice' );
- } else {
- WC()->cart->apply_coupon( '5% OFF' );
- wc_print_notice( 'You just got 5% off your order!', 'notice' );
- }
- wc_clear_notices();
- }
Advertisement
Add Comment
Please, Sign In to add comment