Code Duplication    Length = 16-18 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 1008-1025 (lines=18) @@
1005
	 *
1006
	 * @throws Exception
1007
	 */
1008
	private function validate_product_categories() {
1009
		if ( sizeof( $this->get_product_categories() ) > 0 ) {
1010
			$valid_for_cart = false;
1011
			if ( ! WC()->cart->is_empty() ) {
1012
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1013
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
1014
1015
					// If we find an item with a cat in our allowed cat list, the coupon is valid
1016
					if ( sizeof( array_intersect( $product_cats, $this->get_product_categories() ) ) > 0 ) {
1017
						$valid_for_cart = true;
1018
					}
1019
				}
1020
			}
1021
			if ( ! $valid_for_cart ) {
1022
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
1023
			}
1024
		}
1025
	}
1026
1027
	/**
1028
	 * Ensure coupon is valid for sale items in the cart is valid or throw exception.
@@ 1112-1127 (lines=16) @@
1109
	 *
1110
	 * @throws Exception
1111
	 */
1112
	private function validate_cart_excluded_product_categories() {
1113
		if ( sizeof( $this->get_excluded_product_categories() ) > 0 ) {
1114
			$valid_for_cart = true;
1115
			if ( ! WC()->cart->is_empty() ) {
1116
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1117
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
1118
					if ( sizeof( array_intersect( $product_cats, $this->get_excluded_product_categories() ) ) > 0 ) {
1119
						$valid_for_cart = false;
1120
					}
1121
				}
1122
			}
1123
			if ( ! $valid_for_cart ) {
1124
				throw new Exception( self::E_WC_COUPON_EXCLUDED_CATEGORIES );
1125
			}
1126
		}
1127
	}
1128
1129
	/**
1130
	 * Exclude sale items from cart.