Code Duplication    Length = 17-18 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 439-455 (lines=17) @@
436
	 *
437
	 * @throws Exception
438
	 */
439
	private function validate_product_categories() {
440
		if ( sizeof( $this->product_categories ) > 0 ) {
441
			$valid_for_cart = false;
442
			if ( ! WC()->cart->is_empty() ) {
443
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
444
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
445
446
					// If we find an item with a cat in our allowed cat list, the coupon is valid
447
					if ( sizeof( array_intersect( $product_cats, $this->product_categories ) ) > 0 ) {
448
						$valid_for_cart = true;
449
					}
450
				}
451
			}
452
			if ( ! $valid_for_cart ) {
453
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
454
			}
455
		}
456
	}
457
458
	/**
@@ 543-560 (lines=18) @@
540
	 *
541
	 * @throws Exception
542
	 */
543
	private function validate_cart_excluded_product_categories() {
544
		if ( sizeof( $this->exclude_product_categories ) > 0 ) {
545
			$valid_for_cart = true;
546
			if ( ! WC()->cart->is_empty() ) {
547
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
548
549
					$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
550
551
					if ( sizeof( array_intersect( $product_cats, $this->exclude_product_categories ) ) > 0 ) {
552
						$valid_for_cart = false;
553
					}
554
				}
555
			}
556
			if ( ! $valid_for_cart ) {
557
				throw new Exception( self::E_WC_COUPON_EXCLUDED_CATEGORIES );
558
			}
559
		}
560
	}
561
562
	/**
563
	 * Exclude sale items from cart.