diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index 25362b919a2..2b4e8df9906 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -384,13 +384,13 @@ jQuery( function ( $ ) { if ( value != null ) { wc_meta_boxes_order_items.block(); - var data = { + var data = $.extend( {}, wc_meta_boxes_order_items.get_taxable_address(), { action : 'woocommerce_add_coupon_discount', dataType : 'json', order_id : woocommerce_admin_meta_boxes.post_id, security : woocommerce_admin_meta_boxes.order_item_nonce, coupon : value - }; + } ); $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { if ( response.success ) { @@ -411,13 +411,13 @@ jQuery( function ( $ ) { var $this = $( this ); wc_meta_boxes_order_items.block(); - var data = { + var data = $.extend( {}, wc_meta_boxes_order_items.get_taxable_address(), { action : 'woocommerce_remove_order_coupon', dataType : 'json', order_id : woocommerce_admin_meta_boxes.post_id, security : woocommerce_admin_meta_boxes.order_item_nonce, coupon : $this.data( 'code' ) - }; + } ); $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { if ( response.success ) { diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index 2ba970ab370..1e7bcad99c6 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -1076,14 +1076,24 @@ class WC_AJAX { $response = array(); try { - $order_id = absint( $_POST['order_id'] ); - $order = wc_get_order( $order_id ); - $result = $order->apply_coupon( wc_clean( $_POST['coupon'] ) ); + $order_id = absint( $_POST['order_id'] ); + $order = wc_get_order( $order_id ); + $calculate_tax_args = array( + 'country' => strtoupper( wc_clean( $_POST['country'] ) ), + 'state' => strtoupper( wc_clean( $_POST['state'] ) ), + 'postcode' => strtoupper( wc_clean( $_POST['postcode'] ) ), + 'city' => strtoupper( wc_clean( $_POST['city'] ) ), + ); + + $result = $order->apply_coupon( wc_clean( $_POST['coupon'] ) ); if ( is_wp_error( $result ) ) { throw new Exception( html_entity_decode( wp_strip_all_tags( $result->get_error_message() ) ) ); } + $order->calculate_taxes( $calculate_tax_args ); + $order->calculate_totals( false ); + ob_start(); include 'admin/meta-boxes/views/html-order-items.php'; $response['html'] = ob_get_clean(); @@ -1108,10 +1118,18 @@ class WC_AJAX { $response = array(); try { - $order_id = absint( $_POST['order_id'] ); - $order = wc_get_order( $order_id ); + $order_id = absint( $_POST['order_id'] ); + $order = wc_get_order( $order_id ); + $calculate_tax_args = array( + 'country' => strtoupper( wc_clean( $_POST['country'] ) ), + 'state' => strtoupper( wc_clean( $_POST['state'] ) ), + 'postcode' => strtoupper( wc_clean( $_POST['postcode'] ) ), + 'city' => strtoupper( wc_clean( $_POST['city'] ) ), + ); $order->remove_coupon( wc_clean( $_POST['coupon'] ) ); + $order->calculate_taxes( $calculate_tax_args ); + $order->calculate_totals( false ); ob_start(); include 'admin/meta-boxes/views/html-order-items.php';