WC_Discounts::validate_coupon_sale_items()protectedWC 3.2.0

Ensure coupon is valid for sale items in the list is valid or throw exception.

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

Changelog

Since 3.2.0 Introduced.

WC_Discounts::validate_coupon_sale_items() code WC 8.6.1

protected function validate_coupon_sale_items( $coupon ) {
	if ( $coupon->get_exclude_sale_items() ) {
		$valid = true;

		foreach ( $this->get_items_to_validate() as $item ) {
			if ( $item->product && $item->product->is_on_sale() ) {
				$valid = false;
				break;
			}
		}

		if ( ! $valid ) {
			throw new Exception( __( 'Sorry, this coupon is not valid for sale items.', 'woocommerce' ), 110 );
		}
	}

	return true;
}