Coupon logic fix

This commit is contained in:
Mike Jolley 2011-11-15 22:20:59 +00:00
parent eb1c9f9432
commit b91b7fd4b5
3 changed files with 29 additions and 22 deletions

View File

@ -404,6 +404,8 @@ class woocommerce_cart {
if ($this->applied_coupons) foreach ($this->applied_coupons as $code) :
$coupon = &new woocommerce_coupon( $code );
if ($coupon->type!='fixed_product' && $coupon->type!='percent_product') continue;
$this_item_is_discounted = false;
// Specific product ID's get the discount

View File

@ -62,28 +62,6 @@ class woocommerce_coupon {
if ($this->id) :
// Product ids
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'], $this->product_ids) || in_array($cart_item['variation_id'], $this->product_ids)) :
$valid = true;
endif;
endforeach; endif;
if (!$valid) return false;
endif;
// Exclude product ids
if (sizeof( $this->exclude_product_ids )>0) :
$valid = true;
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'], $this->exclude_product_ids) || in_array($cart_item['variation_id'], $this->exclude_product_ids)) :
$valid = false;
endif;
endforeach; endif;
if (!$valid) return false;
endif;
if ($this->usage_limit>0) :
if ($this->usage_count>$this->usage_limit) :
return false;
@ -96,6 +74,32 @@ class woocommerce_coupon {
endif;
endif;
// Product ids - If a product included is found in the cart then its valid
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'], $this->product_ids) || in_array($cart_item['variation_id'], $this->product_ids)) :
$valid = true;
endif;
endforeach; endif;
if (!$valid) return false;
endif;
// Cart discounts cannot be added if non-eligble product is found in cart
if ($this->type!='fixed_product' && $this->type!='percent_product') :
if (sizeof( $this->exclude_product_ids )>0) :
$valid = true;
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'], $this->exclude_product_ids) || in_array($cart_item['variation_id'], $this->exclude_product_ids)) :
$valid = false;
endif;
endforeach; endif;
if (!$valid) return false;
endif;
endif;
$valid = apply_filters('woocommerce_coupon_is_valid', true, $this);
if (!$valid) return false;

View File

@ -97,6 +97,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
* Option to show size/weight on attributes tab
* Added logger class for debugging
* Ability to make layered nav an "OR" query so you can expand your search rather than filter it
* Tweaked coupon logic. Excluded coupons (for product discounts) don't get a product discount, but valid products do
= 1.2.1 - 10/11/2011 =
* Reworked downloadable and virtual products - now variations can be downloadable/virtual too making it more flexible