Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created February 1, 2012 16:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikejolley/1717863 to your computer and use it in GitHub Desktop.
Save mikejolley/1717863 to your computer and use it in GitHub Desktop.
WooCommmerce - Custom coupon logic
/*
* 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;
}
@redefinered
Copy link

Hi, I can't get the code work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment