|
@@ 929-943 (lines=15) @@
|
| 926 |
|
* |
| 927 |
|
* @throws Exception |
| 928 |
|
*/ |
| 929 |
|
private function validate_product_ids() { |
| 930 |
|
if ( sizeof( $this->get_product_ids() ) > 0 ) { |
| 931 |
|
$valid_for_cart = false; |
| 932 |
|
if ( ! WC()->cart->is_empty() ) { |
| 933 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 934 |
|
if ( in_array( $cart_item['product_id'], $this->get_product_ids() ) || in_array( $cart_item['variation_id'], $this->get_product_ids() ) || in_array( $cart_item['data']->get_parent(), $this->get_product_ids() ) ) { |
| 935 |
|
$valid_for_cart = true; |
| 936 |
|
} |
| 937 |
|
} |
| 938 |
|
} |
| 939 |
|
if ( ! $valid_for_cart ) { |
| 940 |
|
throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE ); |
| 941 |
|
} |
| 942 |
|
} |
| 943 |
|
} |
| 944 |
|
|
| 945 |
|
/** |
| 946 |
|
* Ensure coupon is valid for product categories in the cart is valid or throw exception. |
|
@@ 1032-1047 (lines=16) @@
|
| 1029 |
|
* |
| 1030 |
|
* @throws Exception |
| 1031 |
|
*/ |
| 1032 |
|
private function validate_cart_excluded_product_ids() { |
| 1033 |
|
// Exclude Products |
| 1034 |
|
if ( sizeof( $this->get_excluded_product_ids() ) > 0 ) { |
| 1035 |
|
$valid_for_cart = true; |
| 1036 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1037 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1038 |
|
if ( in_array( $cart_item['product_id'], $this->get_excluded_product_ids() ) || in_array( $cart_item['variation_id'], $this->get_excluded_product_ids() ) || in_array( $cart_item['data']->get_parent(), $this->get_excluded_product_ids() ) ) { |
| 1039 |
|
$valid_for_cart = false; |
| 1040 |
|
} |
| 1041 |
|
} |
| 1042 |
|
} |
| 1043 |
|
if ( ! $valid_for_cart ) { |
| 1044 |
|
throw new Exception( self::E_WC_COUPON_EXCLUDED_PRODUCTS ); |
| 1045 |
|
} |
| 1046 |
|
} |
| 1047 |
|
} |
| 1048 |
|
|
| 1049 |
|
/** |
| 1050 |
|
* Exclude categories from cart. |