Coupon amount validation

This commit is contained in:
claudiulodro 2017-08-10 11:00:57 -07:00
parent db87fc68b9
commit fa35104486
1 changed files with 6 additions and 0 deletions

View File

@ -447,6 +447,12 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @throws WC_Data_Exception
*/
public function set_amount( $amount ) {
if ( $amount < 0 ) {
$this->error( 'coupon_invalid_amount', __( 'Invalid discount amount', 'woocommerce' ) );
}
if ( 'percent' === $this->get_discount_type() && $amount > 100 ) {
$this->error( 'coupon_invalid_amount', __( 'Invalid discount amount', 'woocommerce' ) );
}
$this->set_prop( 'amount', wc_format_decimal( $amount ) );
}