WC_Coupon::set_amount
Set amount.
Метод класса: WC_Coupon{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
$WC_Coupon = new WC_Coupon(); $WC_Coupon->set_amount( $amount );
- $amount(float|строка) (обязательный)
- Amount.
Список изменений
| С версии 3.0.0 | Введена. |
Код WC_Coupon::set_amount() WC Coupon::set amount WC 11.3.0
public function set_amount( $amount ) {
$amount = wc_format_decimal( $amount );
// Remove leading zeros from numeric strings (e.g., "050" becomes "50")
// to ensure clean display of the coupon amount.
if ( '' !== $amount && is_string( $amount ) ) {
$amount = ltrim( $amount, '0' );
if ( '' === $amount || '.' === $amount[0] ) {
$amount = '0' . $amount;
}
}
if ( ! is_numeric( $amount ) ) {
$amount = 0;
}
if ( (float) $amount < 0 ) {
$this->error( 'coupon_invalid_amount', __( 'Invalid discount amount.', 'woocommerce' ) );
}
if ( 'percent' === $this->get_discount_type() && (float) $amount > 100 ) {
$this->error( 'coupon_invalid_amount', __( 'Invalid discount amount.', 'woocommerce' ) );
}
$this->set_prop( 'amount', $amount );
}