WordPress at Your Fingertips
function is not described

WC_Discounts::validate_coupon_excluded_product_ids() protected WC 3.2.0

Exclude products.

{} It's a method of the class: WC_Discounts{}

No Hooks.

Return

true|false.

Usage

// protected - for code of main (parent) or child class
$result = $this->validate_coupon_excluded_product_ids( $coupon );
$coupon(WC_Coupon) (required)
Coupon data.

Changelog

Since 3.2.0 Introduced.

Code of WC_Discounts::validate_coupon_excluded_product_ids() WC 5.6.0

protected function validate_coupon_excluded_product_ids( $coupon ) {
	// Exclude Products.
	if ( count( $coupon->get_excluded_product_ids() ) > 0 ) {
		$products = array();

		foreach ( $this->get_items_to_validate() as $item ) {
			if ( $item->product && in_array( $item->product->get_id(), $coupon->get_excluded_product_ids(), true ) || in_array( $item->product->get_parent_id(), $coupon->get_excluded_product_ids(), true ) ) {
				$products[] = $item->product->get_name();
			}
		}

		if ( ! empty( $products ) ) {
			/* translators: %s: products list */
			throw new Exception( sprintf( __( 'Sorry, this coupon is not applicable to the products: %s.', 'woocommerce' ), implode( ', ', $products ) ), 113 );
		}
	}

	return true;
}