Code Duplication    Length = 15-16 lines in 2 locations

includes/class-wc-coupon.php 2 locations

@@ 917-931 (lines=15) @@
914
	 *
915
	 * @throws Exception
916
	 */
917
	private function validate_product_ids() {
918
		if ( sizeof( $this->get_product_ids() ) > 0 ) {
919
			$valid_for_cart = false;
920
			if ( ! WC()->cart->is_empty() ) {
921
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
922
					if ( in_array( $cart_item['product_id'], $this->get_product_ids() ) || in_array( $cart_item['variation_id'], $this->get_product_ids() ) || in_array( $cart_item['data']->get_parent(), $this->get_product_ids() ) ) {
923
						$valid_for_cart = true;
924
					}
925
				}
926
			}
927
			if ( ! $valid_for_cart ) {
928
				throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
929
			}
930
		}
931
	}
932
933
	/**
934
	 * Ensure coupon is valid for product categories in the cart is valid or throw exception.
@@ 1020-1035 (lines=16) @@
1017
	 *
1018
	 * @throws Exception
1019
	 */
1020
	private function validate_cart_excluded_product_ids() {
1021
		// Exclude Products
1022
		if ( sizeof( $this->get_excluded_product_ids() ) > 0 ) {
1023
			$valid_for_cart = true;
1024
			if ( ! WC()->cart->is_empty() ) {
1025
				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1026
					if ( in_array( $cart_item['product_id'], $this->get_excluded_product_ids() ) || in_array( $cart_item['variation_id'], $this->get_excluded_product_ids() ) || in_array( $cart_item['data']->get_parent(), $this->get_excluded_product_ids() ) ) {
1027
						$valid_for_cart = false;
1028
					}
1029
				}
1030
			}
1031
			if ( ! $valid_for_cart ) {
1032
				throw new Exception( self::E_WC_COUPON_EXCLUDED_PRODUCTS );
1033
			}
1034
		}
1035
	}
1036
1037
	/**
1038
	 * Exclude categories from cart.