Code Duplication    Length = 15-16 lines in 2 locations

includes/class-wc-coupon.php 2 locations

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