|
@@ 1044-1064 (lines=21) @@
|
| 1041 |
|
* |
| 1042 |
|
* @throws Exception |
| 1043 |
|
*/ |
| 1044 |
|
private function validate_sale_items() { |
| 1045 |
|
if ( $this->get_exclude_sale_items() && $this->is_type( wc_get_product_coupon_types() ) ) { |
| 1046 |
|
$valid_for_cart = false; |
| 1047 |
|
$product_ids_on_sale = wc_get_product_ids_on_sale(); |
| 1048 |
|
|
| 1049 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1050 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1051 |
|
if ( ! empty( $cart_item['variation_id'] ) ) { |
| 1052 |
|
if ( ! in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) { |
| 1053 |
|
$valid_for_cart = true; |
| 1054 |
|
} |
| 1055 |
|
} elseif ( ! in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) { |
| 1056 |
|
$valid_for_cart = true; |
| 1057 |
|
} |
| 1058 |
|
} |
| 1059 |
|
} |
| 1060 |
|
if ( ! $valid_for_cart ) { |
| 1061 |
|
throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS ); |
| 1062 |
|
} |
| 1063 |
|
} |
| 1064 |
|
} |
| 1065 |
|
|
| 1066 |
|
/** |
| 1067 |
|
* All exclusion rules must pass at the same time for a product coupon to be valid. |
|
@@ 1146-1165 (lines=20) @@
|
| 1143 |
|
* |
| 1144 |
|
* @throws Exception |
| 1145 |
|
*/ |
| 1146 |
|
private function validate_cart_excluded_sale_items() { |
| 1147 |
|
if ( $this->get_exclude_sale_items() ) { |
| 1148 |
|
$valid_for_cart = true; |
| 1149 |
|
$product_ids_on_sale = wc_get_product_ids_on_sale(); |
| 1150 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1151 |
|
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1152 |
|
if ( ! empty( $cart_item['variation_id'] ) ) { |
| 1153 |
|
if ( in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) { |
| 1154 |
|
$valid_for_cart = false; |
| 1155 |
|
} |
| 1156 |
|
} elseif ( in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) { |
| 1157 |
|
$valid_for_cart = false; |
| 1158 |
|
} |
| 1159 |
|
} |
| 1160 |
|
} |
| 1161 |
|
if ( ! $valid_for_cart ) { |
| 1162 |
|
throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS ); |
| 1163 |
|
} |
| 1164 |
|
} |
| 1165 |
|
} |
| 1166 |
|
|
| 1167 |
|
/** |
| 1168 |
|
* Check if a coupon is valid. |