/**
  * Add a fee to the order.
  * Order must be saved prior to adding items.
  * @param object $fee
  * @return int updated order item ID
  * @throws WC_Data_Exception
  */
 public function add_fee($fee)
 {
     wc_deprecated_function('WC_Order::add_fee', '2.7', 'Create new WC_Order_Item_Fee object and add to order with WC_Order::add_item()');
     $item = new WC_Order_Item_Fee();
     $item->set_props(array('name' => $fee->name, 'tax_class' => $fee->taxable ? $fee->tax_class : 0, 'total' => $fee->amount, 'total_tax' => $fee->tax, 'taxes' => array('total' => $fee->tax_data), 'order_id' => $this->get_id()));
     $item->save();
     $this->add_item($item);
     wc_do_deprecated_action('woocommerce_order_add_fee', array($this->get_id(), $item->get_id(), $fee), '2.7', 'Use woocommerce_new_order_item action instead.');
     return $item->get_id();
 }
 /**
  * Add fees to the order.
  *
  * @param  WC_Order $order
  */
 protected function create_order_fee_lines(&$order)
 {
     foreach (WC()->cart->get_fees() as $fee_key => $fee) {
         $item = new WC_Order_Item_Fee();
         $item->set_props(array('name' => $fee->name, 'tax_class' => $fee->taxable ? $fee->tax_class : 0, 'total' => $fee->amount, 'total_tax' => $fee->tax, 'taxes' => array('total' => $fee->tax_data)));
         // Set this to pass to legacy actions.
         $item->legacy_fee = $fee;
         $item->legacy_fee_key = $fee_key;
         $order->add_item($item);
     }
 }
Esempio n. 3
0
 /**
  * Test: get_fees
  */
 function test_get_fees()
 {
     $object = new WC_Order();
     $item = new WC_Order_Item_Fee();
     $item->set_props(array('name' => 'Some Fee', 'tax_status' => 'taxable', 'total' => '100', 'tax_class' => ''));
     $object->add_item($item);
     $this->assertCount(1, $object->get_fees());
 }