/** * Updates WooTax tax item to reflect changes in cart/shipping tax totals * * @since 4.2 * @param (double) $cart_tax the total cart tax added by WooTax * @param (double) $shipping_tax the total shipping tax added by WooTax */ private function update_tax_item($cart_tax, $shipping_tax) { global $wpdb; // Add a new tax item if necessary $tax_item_id = WT_Orders::get_meta($this->order_id, 'tax_item_id'); if ($tax_item_id == 0 || $tax_item_id == NULL) { $wpdb->insert("{$wpdb->prefix}woocommerce_order_items", array('order_item_type' => 'tax', 'order_item_name' => apply_filters('wootax_rate_code', 'WOOTAX-RATE-DO-NOT-REMOVE'), 'order_id' => $this->order_id)); // Store new tax item ID $tax_item_id = $wpdb->insert_id; WT_Orders::update_meta($this->order_id, 'tax_item_id', $tax_item_id); } // Update tax item meta wc_update_order_item_meta($tax_item_id, 'rate_id', WT_RATE_ID); wc_update_order_item_meta($tax_item_id, 'label', WC_WooTax::get_rate_label(WT_RATE_ID)); wc_update_order_item_meta($tax_item_id, 'name', WC_WooTax::get_rate_label(WT_RATE_ID)); wc_update_order_item_meta($tax_item_id, 'compound', true); wc_update_order_item_meta($tax_item_id, 'tax_amount', $cart_tax); wc_update_order_item_meta($tax_item_id, 'shipping_tax_amount', $shipping_tax); if (WT_SUBS_ACTIVE) { wc_update_order_item_meta($tax_item_id, 'cart_tax', $cart_tax); wc_update_order_item_meta($tax_item_id, 'shipping_tax', $shipping_tax); } }