WC_Checkout::create_order_shipping_lines()
Add shipping lines to the order.
Метод класса: WC_Checkout{}
Хуки из метода
Возвращает
null
. Ничего (null).
Использование
$WC_Checkout = new WC_Checkout(); $WC_Checkout->create_order_shipping_lines( $order, $chosen_shipping_methods, $packages );
- $order(WC_Order) (обязательный) (передается по ссылке — &)
- Order Instance.
- $chosen_shipping_methods(массив) (обязательный)
- Chosen shipping methods.
- $packages(массив) (обязательный)
- Packages.
Код WC_Checkout::create_order_shipping_lines() WC Checkout::create order shipping lines WC 9.3.3
public function create_order_shipping_lines( &$order, $chosen_shipping_methods, $packages ) { foreach ( $packages as $package_key => $package ) { if ( isset( $chosen_shipping_methods[ $package_key ], $package['rates'][ $chosen_shipping_methods[ $package_key ] ] ) ) { $shipping_rate = $package['rates'][ $chosen_shipping_methods[ $package_key ] ]; $item = new WC_Order_Item_Shipping(); $item->legacy_package_key = $package_key; // @deprecated 4.4.0 For legacy actions. $item->set_props( array( 'method_title' => $shipping_rate->label, 'method_id' => $shipping_rate->method_id, 'instance_id' => $shipping_rate->instance_id, 'total' => wc_format_decimal( $shipping_rate->cost ), 'taxes' => array( 'total' => $shipping_rate->taxes, ), ) ); foreach ( $shipping_rate->get_meta_data() as $key => $value ) { $item->add_meta_data( $key, $value, true ); } /** * Action hook to adjust item before save. * * @since 3.0.0 */ do_action( 'woocommerce_checkout_create_order_shipping_item', $item, $package_key, $package, $order ); // Add item to order and save. $order->add_item( $item ); } } }