|
@@ 938-955 (lines=18) @@
|
| 935 |
|
* |
| 936 |
|
* @throws Exception |
| 937 |
|
*/ |
| 938 |
|
private function validate_product_categories() { |
| 939 |
|
if ( sizeof( $this->get_product_categories() ) > 0 ) { |
| 940 |
|
$valid_for_cart = false; |
| 941 |
|
if ( ! WC()->cart->is_empty() ) { |
| 942 |
|
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 943 |
|
$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] ); |
| 944 |
|
|
| 945 |
|
// If we find an item with a cat in our allowed cat list, the coupon is valid |
| 946 |
|
if ( sizeof( array_intersect( $product_cats, $this->get_product_categories() ) ) > 0 ) { |
| 947 |
|
$valid_for_cart = true; |
| 948 |
|
} |
| 949 |
|
} |
| 950 |
|
} |
| 951 |
|
if ( ! $valid_for_cart ) { |
| 952 |
|
throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE ); |
| 953 |
|
} |
| 954 |
|
} |
| 955 |
|
} |
| 956 |
|
|
| 957 |
|
/** |
| 958 |
|
* Ensure coupon is valid for sale items in the cart is valid or throw exception. |
|
@@ 1042-1057 (lines=16) @@
|
| 1039 |
|
* |
| 1040 |
|
* @throws Exception |
| 1041 |
|
*/ |
| 1042 |
|
private function validate_cart_excluded_product_categories() { |
| 1043 |
|
if ( sizeof( $this->get_excluded_product_categories() ) > 0 ) { |
| 1044 |
|
$valid_for_cart = true; |
| 1045 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1046 |
|
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1047 |
|
$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] ); |
| 1048 |
|
if ( sizeof( array_intersect( $product_cats, $this->get_excluded_product_categories() ) ) > 0 ) { |
| 1049 |
|
$valid_for_cart = false; |
| 1050 |
|
} |
| 1051 |
|
} |
| 1052 |
|
} |
| 1053 |
|
if ( ! $valid_for_cart ) { |
| 1054 |
|
throw new Exception( self::E_WC_COUPON_EXCLUDED_CATEGORIES ); |
| 1055 |
|
} |
| 1056 |
|
} |
| 1057 |
|
} |
| 1058 |
|
|
| 1059 |
|
/** |
| 1060 |
|
* Exclude sale items from cart. |