Merge pull request #23137 from woocommerce/fix/23051

Change coupon amount field type based on coupon type
This commit is contained in:
Claudio Sanches 2019-05-22 21:19:03 -03:00 committed by GitHub
commit 17da960abe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -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 {

View File

@ -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' ),
)

View File

@ -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 ) );
}
/**