WordPress at Your Fingertips
function is not described

WC_Discounts::validate_coupon_excluded_items() protected WC 3.2.0

All exclusion rules must pass at the same time for a product coupon to be valid.

{} 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_items( $coupon );
$coupon(WC_Coupon) (required)
Coupon data.

Changelog

Since 3.2.0 Introduced.

Code of WC_Discounts::validate_coupon_excluded_items() WC 5.7.1

protected function validate_coupon_excluded_items( $coupon ) {
	$items = $this->get_items_to_validate();
	if ( ! empty( $items ) && $coupon->is_type( wc_get_product_coupon_types() ) ) {
		$valid = false;

		foreach ( $items as $item ) {
			if ( $item->product && $coupon->is_valid_for_product( $item->product, $item->object ) ) {
				$valid = true;
				break;
			}
		}

		if ( ! $valid ) {
			throw new Exception( __( 'Sorry, this coupon is not applicable to selected products.', 'woocommerce' ), 109 );
		}
	}

	return true;
}