|
@@ 962-982 (lines=21) @@
|
| 959 |
|
* |
| 960 |
|
* @throws Exception |
| 961 |
|
*/ |
| 962 |
|
private function validate_sale_items() { |
| 963 |
|
if ( $this->get_exclude_sale_items() && $this->is_type( wc_get_product_coupon_types() ) ) { |
| 964 |
|
$valid_for_cart = false; |
| 965 |
|
$product_ids_on_sale = wc_get_product_ids_on_sale(); |
| 966 |
|
|
| 967 |
|
if ( ! WC()->cart->is_empty() ) { |
| 968 |
|
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 969 |
|
if ( ! empty( $cart_item['variation_id'] ) ) { |
| 970 |
|
if ( ! in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) { |
| 971 |
|
$valid_for_cart = true; |
| 972 |
|
} |
| 973 |
|
} elseif ( ! in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) { |
| 974 |
|
$valid_for_cart = true; |
| 975 |
|
} |
| 976 |
|
} |
| 977 |
|
} |
| 978 |
|
if ( ! $valid_for_cart ) { |
| 979 |
|
throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS ); |
| 980 |
|
} |
| 981 |
|
} |
| 982 |
|
} |
| 983 |
|
|
| 984 |
|
/** |
| 985 |
|
* All exclusion rules must pass at the same time for a product coupon to be valid. |
|
@@ 1064-1083 (lines=20) @@
|
| 1061 |
|
* |
| 1062 |
|
* @throws Exception |
| 1063 |
|
*/ |
| 1064 |
|
private function validate_cart_excluded_sale_items() { |
| 1065 |
|
if ( $this->get_exclude_sale_items() ) { |
| 1066 |
|
$valid_for_cart = true; |
| 1067 |
|
$product_ids_on_sale = wc_get_product_ids_on_sale(); |
| 1068 |
|
if ( ! WC()->cart->is_empty() ) { |
| 1069 |
|
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 1070 |
|
if ( ! empty( $cart_item['variation_id'] ) ) { |
| 1071 |
|
if ( in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) { |
| 1072 |
|
$valid_for_cart = false; |
| 1073 |
|
} |
| 1074 |
|
} elseif ( in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) { |
| 1075 |
|
$valid_for_cart = false; |
| 1076 |
|
} |
| 1077 |
|
} |
| 1078 |
|
} |
| 1079 |
|
if ( ! $valid_for_cart ) { |
| 1080 |
|
throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS ); |
| 1081 |
|
} |
| 1082 |
|
} |
| 1083 |
|
} |
| 1084 |
|
|
| 1085 |
|
/** |
| 1086 |
|
* Check if a coupon is valid. |