WordPress at Your Fingertips
function is not described

WC_Discounts::validate_coupon_sale_items() protected WC 3.2.0

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

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

Changelog

Since 3.2.0 Introduced.

Code of WC_Discounts::validate_coupon_sale_items() WC 5.6.0

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;
}