|
@@ 1032-1052 (lines=21) @@
|
| 1029 |
|
* |
| 1030 |
|
* @throws Exception |
| 1031 |
|
*/ |
| 1032 |
|
private function validate_sale_items() { |
| 1033 |
|
if ( $this->get_exclude_sale_items() && $this->is_type( wc_get_product_coupon_types() ) ) { |
| 1034 |
|
$valid_for_cart = false; |
| 1035 |
|
$product_ids_on_sale = wc_get_product_ids_on_sale(); |
| 1036 |
|
|
| 1037 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1038 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1039 |
|
if ( ! empty( $cart_item['variation_id'] ) ) { |
| 1040 |
|
if ( ! in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) { |
| 1041 |
|
$valid_for_cart = true; |
| 1042 |
|
} |
| 1043 |
|
} elseif ( ! in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) { |
| 1044 |
|
$valid_for_cart = true; |
| 1045 |
|
} |
| 1046 |
|
} |
| 1047 |
|
} |
| 1048 |
|
if ( ! $valid_for_cart ) { |
| 1049 |
|
throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS ); |
| 1050 |
|
} |
| 1051 |
|
} |
| 1052 |
|
} |
| 1053 |
|
|
| 1054 |
|
/** |
| 1055 |
|
* All exclusion rules must pass at the same time for a product coupon to be valid. |
|
@@ 1134-1153 (lines=20) @@
|
| 1131 |
|
* |
| 1132 |
|
* @throws Exception |
| 1133 |
|
*/ |
| 1134 |
|
private function validate_cart_excluded_sale_items() { |
| 1135 |
|
if ( $this->get_exclude_sale_items() ) { |
| 1136 |
|
$valid_for_cart = true; |
| 1137 |
|
$product_ids_on_sale = wc_get_product_ids_on_sale(); |
| 1138 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1139 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1140 |
|
if ( ! empty( $cart_item['variation_id'] ) ) { |
| 1141 |
|
if ( in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) { |
| 1142 |
|
$valid_for_cart = false; |
| 1143 |
|
} |
| 1144 |
|
} elseif ( in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) { |
| 1145 |
|
$valid_for_cart = false; |
| 1146 |
|
} |
| 1147 |
|
} |
| 1148 |
|
} |
| 1149 |
|
if ( ! $valid_for_cart ) { |
| 1150 |
|
throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS ); |
| 1151 |
|
} |
| 1152 |
|
} |
| 1153 |
|
} |
| 1154 |
|
|
| 1155 |
|
/** |
| 1156 |
|
* Check if a coupon is valid. |