Code Duplication    Length = 15-16 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 418-432 (lines=15) @@
415
	 *
416
	 * @throws Exception
417
	 */
418
	private function validate_product_ids() {
419
		if ( sizeof( $this->product_ids ) > 0 ) {
420
			$valid_for_cart = false;
421
			if ( ! WC()->cart->is_empty() ) {
422
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
423
					if ( in_array( $cart_item['product_id'], $this->product_ids ) || in_array( $cart_item['variation_id'], $this->product_ids ) || in_array( $cart_item['data']->get_parent(), $this->product_ids ) ) {
424
						$valid_for_cart = true;
425
					}
426
				}
427
			}
428
			if ( ! $valid_for_cart ) {
429
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
430
			}
431
		}
432
	}
433
434
	/**
435
	 * Ensure coupon is valid for product categories in the cart is valid or throw exception.
@@ 521-536 (lines=16) @@
518
	 *
519
	 * @throws Exception
520
	 */
521
	private function validate_cart_excluded_product_ids() {
522
		// Exclude Products
523
		if ( sizeof( $this->exclude_product_ids ) > 0 ) {
524
			$valid_for_cart = true;
525
			if ( ! WC()->cart->is_empty() ) {
526
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
527
					if ( in_array( $cart_item['product_id'], $this->exclude_product_ids ) || in_array( $cart_item['variation_id'], $this->exclude_product_ids ) || in_array( $cart_item['data']->get_parent(), $this->exclude_product_ids ) ) {
528
						$valid_for_cart = false;
529
					}
530
				}
531
			}
532
			if ( ! $valid_for_cart ) {
533
				throw new Exception( self::E_WC_COUPON_EXCLUDED_PRODUCTS );
534
			}
535
		}
536
	}
537
538
	/**
539
	 * Exclude categories from cart.