Code Duplication    Length = 20-21 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 974-994 (lines=21) @@
971
	 *
972
	 * @throws Exception
973
	 */
974
	private function validate_sale_items() {
975
		if ( $this->get_exclude_sale_items() && $this->is_type( wc_get_product_coupon_types() ) ) {
976
			$valid_for_cart      = false;
977
			$product_ids_on_sale = wc_get_product_ids_on_sale();
978
979
			if ( ! WC()->cart->is_empty() ) {
980
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
981
					if ( ! empty( $cart_item['variation_id'] ) ) {
982
						if ( ! in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) {
983
							$valid_for_cart = true;
984
						}
985
					} elseif ( ! in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) {
986
						$valid_for_cart = true;
987
					}
988
				}
989
			}
990
			if ( ! $valid_for_cart ) {
991
				throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS );
992
			}
993
		}
994
	}
995
996
	/**
997
	 * All exclusion rules must pass at the same time for a product coupon to be valid.
@@ 1076-1095 (lines=20) @@
1073
	 *
1074
	 * @throws Exception
1075
	 */
1076
	private function validate_cart_excluded_sale_items() {
1077
		if ( $this->get_exclude_sale_items() ) {
1078
			$valid_for_cart = true;
1079
			$product_ids_on_sale = wc_get_product_ids_on_sale();
1080
			if ( ! WC()->cart->is_empty() ) {
1081
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1082
					if ( ! empty( $cart_item['variation_id'] ) ) {
1083
						if ( in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) ) {
1084
							$valid_for_cart = false;
1085
						}
1086
					} elseif ( in_array( $cart_item['product_id'], $product_ids_on_sale, true ) ) {
1087
						$valid_for_cart = false;
1088
					}
1089
				}
1090
			}
1091
			if ( ! $valid_for_cart ) {
1092
				throw new Exception( self::E_WC_COUPON_NOT_VALID_SALE_ITEMS );
1093
			}
1094
		}
1095
	}
1096
1097
	/**
1098
	 * Check if a coupon is valid.