Code Duplication    Length = 15-16 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 995-1009 (lines=15) @@
992
	 *
993
	 * @throws Exception
994
	 */
995
	private function validate_product_ids() {
996
		if ( sizeof( $this->get_product_ids() ) > 0 ) {
997
			$valid_for_cart = false;
998
			if ( ! WC()->cart->is_empty() ) {
999
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1000
					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() ) ) {
1001
						$valid_for_cart = true;
1002
					}
1003
				}
1004
			}
1005
			if ( ! $valid_for_cart ) {
1006
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
1007
			}
1008
		}
1009
	}
1010
1011
	/**
1012
	 * Ensure coupon is valid for product categories in the cart is valid or throw exception.
@@ 1098-1113 (lines=16) @@
1095
	 *
1096
	 * @throws Exception
1097
	 */
1098
	private function validate_cart_excluded_product_ids() {
1099
		// Exclude Products
1100
		if ( sizeof( $this->get_excluded_product_ids() ) > 0 ) {
1101
			$valid_for_cart = true;
1102
			if ( ! WC()->cart->is_empty() ) {
1103
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1104
					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() ) ) {
1105
						$valid_for_cart = false;
1106
					}
1107
				}
1108
			}
1109
			if ( ! $valid_for_cart ) {
1110
				throw new Exception( self::E_WC_COUPON_EXCLUDED_PRODUCTS );
1111
			}
1112
		}
1113
	}
1114
1115
	/**
1116
	 * Exclude categories from cart.