Code Duplication    Length = 16-18 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 998-1015 (lines=18) @@
995
	 *
996
	 * @throws Exception
997
	 */
998
	private function validate_product_categories() {
999
		if ( sizeof( $this->get_product_categories() ) > 0 ) {
1000
			$valid_for_cart = false;
1001
			if ( ! WC()->cart->is_empty() ) {
1002
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1003
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
1004
1005
					// If we find an item with a cat in our allowed cat list, the coupon is valid
1006
					if ( sizeof( array_intersect( $product_cats, $this->get_product_categories() ) ) > 0 ) {
1007
						$valid_for_cart = true;
1008
					}
1009
				}
1010
			}
1011
			if ( ! $valid_for_cart ) {
1012
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
1013
			}
1014
		}
1015
	}
1016
1017
	/**
1018
	 * Ensure coupon is valid for sale items in the cart is valid or throw exception.
@@ 1102-1117 (lines=16) @@
1099
	 *
1100
	 * @throws Exception
1101
	 */
1102
	private function validate_cart_excluded_product_categories() {
1103
		if ( sizeof( $this->get_excluded_product_categories() ) > 0 ) {
1104
			$valid_for_cart = true;
1105
			if ( ! WC()->cart->is_empty() ) {
1106
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1107
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
1108
					if ( sizeof( array_intersect( $product_cats, $this->get_excluded_product_categories() ) ) > 0 ) {
1109
						$valid_for_cart = false;
1110
					}
1111
				}
1112
			}
1113
			if ( ! $valid_for_cart ) {
1114
				throw new Exception( self::E_WC_COUPON_EXCLUDED_CATEGORIES );
1115
			}
1116
		}
1117
	}
1118
1119
	/**
1120
	 * Exclude sale items from cart.