Created
February 1, 2012 16:27
-
-
Save mikejolley/1717863 to your computer and use it in GitHub Desktop.
WooCommmerce - Custom coupon logic
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
/* | |
* This code goes into your theme's functions.php | |
*/ | |
add_filter( 'woocommerce_coupon_is_valid', 'custom_woocommerce_coupon_is_valid', 1, 2 ); | |
function custom_woocommerce_coupon_is_valid( $valid, $coupon ) { | |
if ($coupon=='YOURCOUPONCODE') { | |
$min_quantity = 12; | |
if (sizeof( $this->product_ids )>0) { | |
$valid = false; | |
if (sizeof($woocommerce->cart->get_cart())>0) { | |
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) { | |
if (in_array($cart_item['product_id'], $coupon->product_ids) || in_array($cart_item['variation_id'], $coupon->product_ids)) { | |
if ( $cart_item['qty'] > $min_quantity ) $valid = true; | |
} | |
} | |
} | |
} | |
} | |
return $valid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I can't get the code work.