diff --git a/assets/js/admin/meta-boxes-coupon.js b/assets/js/admin/meta-boxes-coupon.js index 4e5377c3abb..0b2e05d5567 100644 --- a/assets/js/admin/meta-boxes-coupon.js +++ b/assets/js/admin/meta-boxes-coupon.js @@ -21,6 +21,12 @@ jQuery(function( $ ) { // Get value var select_val = $( this ).val(); + if ( 'percent' === select_val ) { + $( '#coupon_amount' ).removeClass( 'wc_input_price' ).addClass( 'wc_input_decimal' ); + } else { + $( '#coupon_amount' ).removeClass( 'wc_input_decimal' ).addClass( 'wc_input_price' ); + } + if ( select_val !== 'fixed_cart' ) { $( '.limit_usage_to_x_items_field' ).show(); } else { diff --git a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php index b95e09a34ab..aaf736142ab 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php @@ -90,7 +90,7 @@ class WC_Meta_Box_Coupon_Data { 'label' => __( 'Coupon amount', 'woocommerce' ), 'placeholder' => wc_format_localized_price( 0 ), 'description' => __( 'Value of the coupon.', 'woocommerce' ), - 'data_type' => 'price', + 'data_type' => 'percent' === $coupon->get_discount_type( 'edit' ) ? 'decimal' : 'price', 'desc_tip' => true, 'value' => $coupon->get_amount( 'edit' ), ) diff --git a/includes/class-wc-coupon.php b/includes/class-wc-coupon.php index 617b07da123..181c807368d 100644 --- a/includes/class-wc-coupon.php +++ b/includes/class-wc-coupon.php @@ -199,7 +199,7 @@ class WC_Coupon extends WC_Legacy_Coupon { * @return float */ public function get_amount( $context = 'view' ) { - return (float) $this->get_prop( 'amount', $context ); + return wc_format_decimal( $this->get_prop( 'amount', $context ) ); } /**