Automattic\WooCommerce\StoreApi\Utilities

OrderController::update_order_from_cart()publicWC 1.0

Update an order using data from the current cart.

{} Это метод класса: OrderController{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$OrderController = new OrderController();
$OrderController->update_order_from_cart( $order );
$order(\WC_Order) (обязательный)
The order object to update.

Код OrderController::update_order_from_cart() WC 7.1.0

public function update_order_from_cart( \WC_Order $order ) {
	// Ensures Local pickups are accounted for.
	add_filter( 'woocommerce_order_get_tax_location', array( $this, 'handle_local_pickup_taxes' ) );

	// Ensure cart is current.
	wc()->cart->calculate_shipping();
	wc()->cart->calculate_totals();

	// Update the current order to match the current cart.
	$this->update_line_items_from_cart( $order );
	$this->update_addresses_from_cart( $order );
	$order->set_currency( get_woocommerce_currency() );
	$order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
	$order->set_customer_id( get_current_user_id() );
	$order->set_customer_ip_address( \WC_Geolocation::get_ip_address() );
	$order->set_customer_user_agent( wc_get_user_agent() );
	$order->update_meta_data( 'is_vat_exempt', wc()->cart->get_customer()->get_is_vat_exempt() ? 'yes' : 'no' );
	$order->calculate_totals();
}