|
@@ 950-967 (lines=18) @@
|
| 947 |
|
* |
| 948 |
|
* @throws Exception |
| 949 |
|
*/ |
| 950 |
|
private function validate_product_categories() { |
| 951 |
|
if ( sizeof( $this->get_product_categories() ) > 0 ) { |
| 952 |
|
$valid_for_cart = false; |
| 953 |
|
if ( ! WC()->cart->is_empty() ) { |
| 954 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 955 |
|
$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] ); |
| 956 |
|
|
| 957 |
|
// If we find an item with a cat in our allowed cat list, the coupon is valid |
| 958 |
|
if ( sizeof( array_intersect( $product_cats, $this->get_product_categories() ) ) > 0 ) { |
| 959 |
|
$valid_for_cart = true; |
| 960 |
|
} |
| 961 |
|
} |
| 962 |
|
} |
| 963 |
|
if ( ! $valid_for_cart ) { |
| 964 |
|
throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE ); |
| 965 |
|
} |
| 966 |
|
} |
| 967 |
|
} |
| 968 |
|
|
| 969 |
|
/** |
| 970 |
|
* Ensure coupon is valid for sale items in the cart is valid or throw exception. |
|
@@ 1054-1069 (lines=16) @@
|
| 1051 |
|
* |
| 1052 |
|
* @throws Exception |
| 1053 |
|
*/ |
| 1054 |
|
private function validate_cart_excluded_product_categories() { |
| 1055 |
|
if ( sizeof( $this->get_excluded_product_categories() ) > 0 ) { |
| 1056 |
|
$valid_for_cart = true; |
| 1057 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1058 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1059 |
|
$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] ); |
| 1060 |
|
if ( sizeof( array_intersect( $product_cats, $this->get_excluded_product_categories() ) ) > 0 ) { |
| 1061 |
|
$valid_for_cart = false; |
| 1062 |
|
} |
| 1063 |
|
} |
| 1064 |
|
} |
| 1065 |
|
if ( ! $valid_for_cart ) { |
| 1066 |
|
throw new Exception( self::E_WC_COUPON_EXCLUDED_CATEGORIES ); |
| 1067 |
|
} |
| 1068 |
|
} |
| 1069 |
|
} |
| 1070 |
|
|
| 1071 |
|
/** |
| 1072 |
|
* Exclude sale items from cart. |