Created
January 24, 2014 08:20
-
-
Save jwebcat/8593855 to your computer and use it in GitHub Desktop.
Automatically apply coupon to cart WooCommerce
This file contains 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
add_action( 'woocommerce_before_cart', 'apply_matched_coupons' ); | |
function apply_matched_coupons() { | |
global $woocommerce; | |
$get1 = 'getonech'; // your coupon code here | |
$get2 = 'gettwoch'; // your coupon code here | |
$get3 = 'getthreech'; // your coupon code here | |
$get4 = 'getfourch'; // your coupon code here | |
$get5 = 'getfivech'; // your coupon code here | |
if ( $woocommerce->cart->cart_contents_count >= 1 && $woocommerce->cart->cart_contents_count < 2 ) { | |
$woocommerce->cart->add_discount( $get1 ); | |
$woocommerce->show_messages(); | |
} elseif ( $woocommerce->cart->cart_contents_count >= 2 && $woocommerce->cart->cart_contents_count < 3 ) { | |
$woocommerce->cart->add_discount( $get2 ); | |
$woocommerce->show_messages(); | |
} elseif ( $woocommerce->cart->cart_contents_count >= 3 && $woocommerce->cart->cart_contents_count < 4 ) { | |
$woocommerce->cart->add_discount( $get3 ); | |
$woocommerce->show_messages(); | |
} elseif ( $woocommerce->cart->cart_contents_count >= 4 && $woocommerce->cart->cart_contents_count < 5 ) { | |
$woocommerce->cart->add_discount( $get4 ); | |
$woocommerce->show_messages(); | |
} elseif ( $woocommerce->cart->cart_contents_count >= 5 ) { | |
$woocommerce->cart->add_discount( $get5 ); | |
$woocommerce->show_messages(); | |
} | |
} |
Hello, i have a question. i configured a rule on my woocomerce->coupon (for example apply a coupon discount when min spend is 27$). Now when I want to pay the bill, always appear: do you have any coupon? please enter the code....... Then i only want that this message appear only when the bill is >27$.
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can this be done not with quantity but with the total (Before taxes, and transport)?