Code Duplication    Length = 20-21 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 1022-1042 (lines=21) @@
1019
	 *
1020
	 * @throws Exception
1021
	 */
1022
	private function validate_sale_items() {
1023
		if ( $this->get_exclude_sale_items() && $this->is_type( wc_get_product_coupon_types() ) ) {
1024
			$valid_for_cart      = false;
1025
			$product_ids_on_sale = wc_get_product_ids_on_sale();
1026
1027
			if ( ! WC()->cart->is_empty() ) {
1028
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1029
					if ( ! empty( $cart_item['variation_id'] ) ) {
1030
						if ( ! in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) {
1031
							$valid_for_cart = true;
1032
						}
1033
					} elseif ( ! in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) {
1034
						$valid_for_cart = true;
1035
					}
1036
				}
1037
			}
1038
			if ( ! $valid_for_cart ) {
1039
				throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS );
1040
			}
1041
		}
1042
	}
1043
1044
	/**
1045
	 * All exclusion rules must pass at the same time for a product coupon to be valid.
@@ 1124-1143 (lines=20) @@
1121
	 *
1122
	 * @throws Exception
1123
	 */
1124
	private function validate_cart_excluded_sale_items() {
1125
		if ( $this->get_exclude_sale_items() ) {
1126
			$valid_for_cart = true;
1127
			$product_ids_on_sale = wc_get_product_ids_on_sale();
1128
			if ( ! WC()->cart->is_empty() ) {
1129
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1130
					if ( ! empty( $cart_item['variation_id'] ) ) {
1131
						if ( in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) {
1132
							$valid_for_cart = false;
1133
						}
1134
					} elseif ( in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) {
1135
						$valid_for_cart = false;
1136
					}
1137
				}
1138
			}
1139
			if ( ! $valid_for_cart ) {
1140
				throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS );
1141
			}
1142
		}
1143
	}
1144
1145
	/**
1146
	 * Check if a coupon is valid.