Code Duplication    Length = 16-18 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 1016-1033 (lines=18) @@
1013
	 *
1014
	 * @throws Exception
1015
	 */
1016
	private function validate_product_categories() {
1017
		if ( sizeof( $this->get_product_categories() ) > 0 ) {
1018
			$valid_for_cart = false;
1019
			if ( ! WC()->cart->is_empty() ) {
1020
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1021
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
1022
1023
					// If we find an item with a cat in our allowed cat list, the coupon is valid
1024
					if ( sizeof( array_intersect( $product_cats, $this->get_product_categories() ) ) > 0 ) {
1025
						$valid_for_cart = true;
1026
					}
1027
				}
1028
			}
1029
			if ( ! $valid_for_cart ) {
1030
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
1031
			}
1032
		}
1033
	}
1034
1035
	/**
1036
	 * Ensure coupon is valid for sale items in the cart is valid or throw exception.
@@ 1120-1135 (lines=16) @@
1117
	 *
1118
	 * @throws Exception
1119
	 */
1120
	private function validate_cart_excluded_product_categories() {
1121
		if ( sizeof( $this->get_excluded_product_categories() ) > 0 ) {
1122
			$valid_for_cart = true;
1123
			if ( ! WC()->cart->is_empty() ) {
1124
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1125
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
1126
					if ( sizeof( array_intersect( $product_cats, $this->get_excluded_product_categories() ) ) > 0 ) {
1127
						$valid_for_cart = false;
1128
					}
1129
				}
1130
			}
1131
			if ( ! $valid_for_cart ) {
1132
				throw new Exception( self::E_WC_COUPON_EXCLUDED_CATEGORIES );
1133
			}
1134
		}
1135
	}
1136
1137
	/**
1138
	 * Exclude sale items from cart.