Code Duplication    Length = 16-18 lines in 2 locations

includes/class-wc-coupon.php 2 locations

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