improved the add_order_tax ajax method
This commit is contained in:
parent
5b3f69de0a
commit
93b464cb29
|
@ -1076,35 +1076,13 @@ class WC_AJAX {
|
||||||
|
|
||||||
$order_id = absint( $_POST['order_id'] );
|
$order_id = absint( $_POST['order_id'] );
|
||||||
$rate_id = absint( $_POST['rate_id'] );
|
$rate_id = absint( $_POST['rate_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 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return HTML items
|
|
||||||
$order = new WC_Order( $order_id );
|
$order = new WC_Order( $order_id );
|
||||||
$data = get_post_meta( $order_id );
|
$data = get_post_meta( $order_id );
|
||||||
|
|
||||||
|
// Add new tax
|
||||||
|
$order->add_tax( $rate_id, 0, 0 );
|
||||||
|
|
||||||
|
// Return HTML items
|
||||||
include( 'admin/meta-boxes/views/html-order-items.php' );
|
include( 'admin/meta-boxes/views/html-order-items.php' );
|
||||||
|
|
||||||
die();
|
die();
|
||||||
|
|
Loading…
Reference in New Issue