WC_Discounts::validate_coupon_maximum_amountprotectedWC 3.2.0

Ensure coupon amount is valid or throw exception.

Метод класса: WC_Discounts{}

Хуки из метода

Возвращает

true|false.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_coupon_maximum_amount( $coupon );
$coupon(WC_Coupon) (обязательный)
Coupon data.

Список изменений

С версии 3.2.0 Введена.

Код WC_Discounts::validate_coupon_maximum_amount() WC 10.9.4

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

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

	return true;
}