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.
@@ 525-540 (lines=16) @@
522
	 *
523
	 * @throws Exception
524
	 */
525
	private function validate_cart_excluded_product_ids() {
526
		// Exclude Products
527
		if ( sizeof( $this->exclude_product_ids ) > 0 ) {
528
			$valid_for_cart = true;
529
			if ( ! WC()->cart->is_empty() ) {
530
				foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
531
					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 ) ) {
532
						$valid_for_cart = false;
533
					}
534
				}
535
			}
536
			if ( ! $valid_for_cart ) {
537
				throw new Exception( self::E_WC_COUPON_EXCLUDED_PRODUCTS );
538
			}
539
		}
540
	}
541
542
	/**
543
	 * Exclude categories from cart.