Code Duplication    Length = 15-16 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 977-991 (lines=15) @@
974
	 *
975
	 * @throws Exception
976
	 */
977
	private function validate_product_ids() {
978
		if ( sizeof( $this->get_product_ids() ) > 0 ) {
979
			$valid_for_cart = false;
980
			if ( ! WC()->cart->is_empty() ) {
981
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
982
					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() ) ) {
983
						$valid_for_cart = true;
984
					}
985
				}
986
			}
987
			if ( ! $valid_for_cart ) {
988
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
989
			}
990
		}
991
	}
992
993
	/**
994
	 * Ensure coupon is valid for product categories in the cart is valid or throw exception.
@@ 1080-1095 (lines=16) @@
1077
	 *
1078
	 * @throws Exception
1079
	 */
1080
	private function validate_cart_excluded_product_ids() {
1081
		// Exclude Products
1082
		if ( sizeof( $this->get_excluded_product_ids() ) > 0 ) {
1083
			$valid_for_cart = true;
1084
			if ( ! WC()->cart->is_empty() ) {
1085
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1086
					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() ) ) {
1087
						$valid_for_cart = false;
1088
					}
1089
				}
1090
			}
1091
			if ( ! $valid_for_cart ) {
1092
				throw new Exception( self::E_WC_COUPON_EXCLUDED_PRODUCTS );
1093
			}
1094
		}
1095
	}
1096
1097
	/**
1098
	 * Exclude categories from cart.