Code Duplication    Length = 20-21 lines in 2 locations

includes/class-wc-coupon.php 2 locations

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