Skip to content

Instantly share code, notes, and snippets.

@AdsonCicilioti
Forked from jwebcat/auto-coupon-woo.php
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdsonCicilioti/a30b71c87c904c485ace to your computer and use it in GitHub Desktop.
Save AdsonCicilioti/a30b71c87c904c485ace to your computer and use it in GitHub Desktop.
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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment