WC_Discounts::validate_coupon_minimum_amountprotectedWC 3.2.0

Ensure coupon amount is valid or throw exception.

Method of the class: WC_Discounts{}

Returns

true|false.

Usage

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

Changelog

Since 3.2.0 Introduced.

WC_Discounts::validate_coupon_minimum_amount() code WC 10.6.2

protected function validate_coupon_minimum_amount( $coupon ) {
	$subtotal = wc_remove_number_precision( $this->get_object_subtotal() );

	if ( $coupon->get_minimum_amount() > 0 && apply_filters( 'woocommerce_coupon_validate_minimum_amount', $coupon->get_minimum_amount() > $subtotal, $coupon, $subtotal ) ) {
		$allowed_tags = array(
			'span'  => array(
				'class' => true,
			),
			'bdi'   => true,
			'small' => true,
		);
		throw new Exception(
			sprintf(
				/* translators: %1$s: coupon code, %2$s: coupon minimum amount */
				esc_html__( 'The minimum spend for coupon "%1$s" is %2$s.', 'woocommerce' ),
				esc_html( $coupon->get_code() ),
				wp_kses( wc_price( $coupon->get_minimum_amount() ), $allowed_tags )
			),
			108
		);
	}

	return true;
}