Code Duplication    Length = 20-21 lines in 2 locations

includes/class-wc-coupon.php 2 locations

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