From 86fb87c7d169882dadc91e79cef2326f696e7f7c Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 25 Mar 2019 14:55:14 +0000 Subject: [PATCH 1/3] Change coupon amount type based on coupon type --- assets/js/admin/meta-boxes-coupon.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/js/admin/meta-boxes-coupon.js b/assets/js/admin/meta-boxes-coupon.js index 4e5377c3abb..46859de6536 100644 --- a/assets/js/admin/meta-boxes-coupon.js +++ b/assets/js/admin/meta-boxes-coupon.js @@ -23,8 +23,10 @@ jQuery(function( $ ) { if ( select_val !== 'fixed_cart' ) { $( '.limit_usage_to_x_items_field' ).show(); + $( '#coupon_amount' ).removeClass( 'wc_input_price' ).addClass( 'wc_input_decimal' ); } else { $( '.limit_usage_to_x_items_field' ).hide(); + $( '#coupon_amount' ).removeClass( 'wc_input_decimal' ).addClass( 'wc_input_price' ); } } }; From 1e0ed1d20c12e8763cbcbebf7eeb0f40bbf76699 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 25 Mar 2019 14:56:27 +0000 Subject: [PATCH 2/3] Target only percent --- assets/js/admin/meta-boxes-coupon.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/assets/js/admin/meta-boxes-coupon.js b/assets/js/admin/meta-boxes-coupon.js index 46859de6536..0b2e05d5567 100644 --- a/assets/js/admin/meta-boxes-coupon.js +++ b/assets/js/admin/meta-boxes-coupon.js @@ -21,13 +21,17 @@ jQuery(function( $ ) { // Get value var select_val = $( this ).val(); - if ( select_val !== 'fixed_cart' ) { - $( '.limit_usage_to_x_items_field' ).show(); + if ( 'percent' === select_val ) { $( '#coupon_amount' ).removeClass( 'wc_input_price' ).addClass( 'wc_input_decimal' ); } else { - $( '.limit_usage_to_x_items_field' ).hide(); $( '#coupon_amount' ).removeClass( 'wc_input_decimal' ).addClass( 'wc_input_price' ); } + + if ( select_val !== 'fixed_cart' ) { + $( '.limit_usage_to_x_items_field' ).show(); + } else { + $( '.limit_usage_to_x_items_field' ).hide(); + } } }; From eb45b94edbd4b2ed6cbfa55e0c2d6e7bbabc71fe Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 25 Mar 2019 15:10:56 +0000 Subject: [PATCH 3/3] Switch data_type --- includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php | 2 +- includes/class-wc-coupon.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 c3d28ccaa4e..74fc455110f 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 ) ); } /**