WC_Order_Item_Product::set_backorder_meta PHP Method

set_backorder_meta() public method

Set meta data for backordered products.
public set_backorder_meta ( )
    public function set_backorder_meta()
    {
        if ($this->get_product()->backorders_require_notification() && $this->get_product()->is_on_backorder($this->get_quantity())) {
            $this->add_meta_data(apply_filters('woocommerce_backordered_item_meta_name', __('Backordered', 'woocommerce')), $this->get_quantity() - max(0, $this->get_product()->get_stock_quantity()), true);
        }
    }

Usage Example

 /**
  * Add line items to the order.
  *
  * @param  WC_Order $order
  */
 protected function create_order_line_items(&$order)
 {
     foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
         $product = $values['data'];
         $item = new WC_Order_Item_Product();
         $item->set_props(array('quantity' => $values['quantity'], 'name' => $product ? $product->get_name() : '', 'tax_class' => $product ? $product->get_tax_class() : '', 'product_id' => $product ? $product->is_type('variation') ? $product->get_parent_id() : $product->get_id() : 0, 'variation_id' => $product && $product->is_type('variation') ? $product->get_id() : 0, 'variation' => $values['variation'], 'subtotal' => $values['line_subtotal'], 'total' => $values['line_total'], 'subtotal_tax' => $values['line_subtotal_tax'], 'total_tax' => $values['line_tax'], 'taxes' => $values['line_tax_data']));
         $item->set_backorder_meta();
         // Set this to pass to legacy actions.
         $item->legacy_values = $values;
         $item->legacy_cart_item_key = $cart_item_key;
         $order->add_item($item);
     }
 }
All Usage Examples Of WC_Order_Item_Product::set_backorder_meta