/**
  * Add a tax row to the order.
  * @param array $args
  * @param int $tax_amount amount of tax.
  * @param int $shipping_tax_amount shipping amount.
  * @return int order item ID
  */
 public function add_tax($tax_rate_id, $tax_amount = 0, $shipping_tax_amount = 0)
 {
     _deprecated_function('WC_Order::add_tax', '2.7', 'Create new WC_Order_Item_Tax object and add to order with WC_Order::add_item()');
     $item = new WC_Order_Item_Tax(array('rate_id' => $tax_rate_id, 'tax_total' => $tax_amount, 'shipping_tax_total' => $shipping_tax_amount));
     $item->set_rate($tax_rate_id);
     $item->set_order_id($this->get_id());
     $item->save();
     $this->add_item($item);
     wc_do_deprecated_action('woocommerce_order_add_tax', array($this->get_id(), $item->get_id(), $tax_rate_id, $tax_amount, $shipping_tax_amount), '2.7', 'Use woocommerce_new_order_item action instead.');
     return $item->get_id();
 }
Exemplo n.º 2
0
 /**
  * Add order tax column via ajax.
  */
 public static function add_order_tax()
 {
     global $wpdb;
     check_ajax_referer('order-item', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     try {
         $order_id = absint($_POST['order_id']);
         $rate_id = absint($_POST['rate_id']);
         $order = wc_get_order($order_id);
         $data = get_post_meta($order_id);
         // Add new tax
         $item = new WC_Order_Item_Tax();
         $item->set_rate($rate_id);
         $item->set_order_id($order_id);
         $item->save();
         ob_start();
         include 'admin/meta-boxes/views/html-order-items.php';
         wp_send_json_success(array('html' => ob_get_clean()));
     } catch (Exception $e) {
         wp_send_json_error(array('error' => $e->getMessage()));
     }
     die;
 }
Exemplo n.º 3
0
 /**
  * Add order tax column via ajax.
  */
 public static function add_order_tax()
 {
     global $wpdb;
     check_ajax_referer('order-item', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     $order_id = absint($_POST['order_id']);
     $rate_id = absint($_POST['rate_id']);
     $order = wc_get_order($order_id);
     $data = get_post_meta($order_id);
     // Add new tax
     $item = new WC_Order_Item_Tax();
     $item->set_rate($rate_id);
     $item->set_order_id($order_id);
     $item->save();
     // Return HTML items
     include 'admin/meta-boxes/views/html-order-items.php';
     die;
 }