Additional check for product coupons and sale product exclusion. Fixes #5697

This commit is contained in:
Mike Jolley 2014-06-25 13:46:47 +01:00
parent 1389dd2e86
commit 6390e387e2
2 changed files with 19 additions and 1 deletions

View File

@ -452,7 +452,7 @@ class WC_Product {
* @return int
*/
public function get_parent() {
return apply_filters('woocommerce_product_parent', $this->post->post_parent, $this);
return apply_filters( 'woocommerce_product_parent', absint( $this->post->post_parent ), $this );
}
/**

View File

@ -351,6 +351,24 @@ class WC_Coupon {
}
}
// Exclude Sale Items check for product coupons - valid if a non-sale item is present
if ( 'yes' === $this->exclude_sale_items && in_array( $this->type, array( 'fixed_product', 'percent_product' ) ) ) {
$valid_for_cart = false;
$product_ids_on_sale = wc_get_product_ids_on_sale();
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( sizeof( array_intersect( array( absint( $cart_item['product_id'] ), absint( $cart_item['variation_id'] ), $cart_item['data']->get_parent() ), $product_ids_on_sale ) ) === 0 ) {
// not on sale
$valid_for_cart = true;
}
}
}
if ( ! $valid_for_cart ) {
$valid = false;
$error_code = self::E_WC_COUPON_NOT_VALID_SALE_ITEMS;
}
}
// Cart discounts cannot be added if non-eligble product is found in cart
if ( $this->type != 'fixed_product' && $this->type != 'percent_product' ) {