Code Duplication    Length = 15-16 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 987-1001 (lines=15) @@
984
	 *
985
	 * @throws Exception
986
	 */
987
	private function validate_product_ids() {
988
		if ( sizeof( $this->get_product_ids() ) > 0 ) {
989
			$valid_for_cart = false;
990
			if ( ! WC()->cart->is_empty() ) {
991
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
992
					if ( in_array( $cart_item['product_id'], $this->get_product_ids() ) || in_array( $cart_item['variation_id'], $this->get_product_ids() ) || in_array( $cart_item['data']->get_parent(), $this->get_product_ids() ) ) {
993
						$valid_for_cart = true;
994
					}
995
				}
996
			}
997
			if ( ! $valid_for_cart ) {
998
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
999
			}
1000
		}
1001
	}
1002
1003
	/**
1004
	 * Ensure coupon is valid for product categories in the cart is valid or throw exception.
@@ 1090-1105 (lines=16) @@
1087
	 *
1088
	 * @throws Exception
1089
	 */
1090
	private function validate_cart_excluded_product_ids() {
1091
		// Exclude Products
1092
		if ( sizeof( $this->get_excluded_product_ids() ) > 0 ) {
1093
			$valid_for_cart = true;
1094
			if ( ! WC()->cart->is_empty() ) {
1095
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1096
					if ( in_array( $cart_item['product_id'], $this->get_excluded_product_ids() ) || in_array( $cart_item['variation_id'], $this->get_excluded_product_ids() ) || in_array( $cart_item['data']->get_parent(), $this->get_excluded_product_ids() ) ) {
1097
						$valid_for_cart = false;
1098
					}
1099
				}
1100
			}
1101
			if ( ! $valid_for_cart ) {
1102
				throw new Exception( self::E_WC_COUPON_EXCLUDED_PRODUCTS );
1103
			}
1104
		}
1105
	}
1106
1107
	/**
1108
	 * Exclude categories from cart.