Code Duplication    Length = 15-16 lines in 2 locations

includes/class-wc-coupon.php 2 locations

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