WC_Coupon::set_amount
Set amount.
Method of the class: WC_Coupon{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Coupon = new WC_Coupon(); $WC_Coupon->set_amount( $amount );
- $amount(float|string) (required)
- Amount.
Changelog
| Since 3.0.0 | Introduced. |
WC_Coupon::set_amount() WC Coupon::set amount code WC 10.5.0
public function set_amount( $amount ) {
$amount = wc_format_decimal( $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 );
}