From 93b464cb292487cbea4b61a5337322e8751353c5 Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Thu, 24 Jul 2014 17:37:02 -0300 Subject: [PATCH] improved the add_order_tax ajax method --- includes/class-wc-ajax.php | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index 7f1cb8cdd2b..5faaae3c20d 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -1076,35 +1076,13 @@ class WC_AJAX { $order_id = absint( $_POST['order_id'] ); $rate_id = absint( $_POST['rate_id'] ); + $order = new WC_Order( $order_id ); + $data = get_post_meta( $order_id ); - $rate = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $rate_id ) ); - $label = $rate->tax_rate_name ? $rate->tax_rate_name : WC()->countries->tax_or_vat(); - $compound = $rate->tax_rate_compound ? 1 : 0; - $code = array(); - $code[] = $rate->tax_rate_country; - $code[] = $rate->tax_rate_state; - $code[] = $rate->tax_rate_name ? $rate->tax_rate_name : 'TAX'; - $code[] = absint( $rate->tax_rate_priority ); - $code = strtoupper( implode( '-', array_filter( $code ) ) ); - - // Add line item - $new_id = wc_add_order_item( $order_id, array( - 'order_item_name' => wc_clean( $code ), - 'order_item_type' => 'tax' - ) ); - - // Add line item meta - if ( $new_id ) { - wc_add_order_item_meta( $new_id, 'rate_id', $rate_id ); - wc_add_order_item_meta( $new_id, 'label', $label ); - wc_add_order_item_meta( $new_id, 'compound', $compound ); - wc_add_order_item_meta( $new_id, 'tax_amount', wc_format_decimal( 0 ) ); - wc_add_order_item_meta( $new_id, 'shipping_tax_amount', wc_format_decimal( 0 ) ); - } + // Add new tax + $order->add_tax( $rate_id, 0, 0 ); // Return HTML items - $order = new WC_Order( $order_id ); - $data = get_post_meta( $order_id ); include( 'admin/meta-boxes/views/html-order-items.php' ); die();