Automattic\WooCommerce\StoreApi\Utilities
OrderController::update_order_from_cart
Update an order using data from the current cart.
Method of the class: OrderController{}
No Hooks.
Returns
null. Nothing (null).
Usage
$OrderController = new OrderController(); $OrderController->update_order_from_cart( $order, $update_totals );
- $order(WC_Order) (required)
- The order object to update.
- $update_totals(true|false)
- Whether to update totals or not.
Default:true
OrderController::update_order_from_cart() OrderController::update order from cart code WC 11.0.1
public function update_order_from_cart( \WC_Order $order, $update_totals = true ) {
// Tax location for local pickup orders is handled by ShippingController::filter_order_tax_location(), which
// hooks woocommerce_order_get_tax_location once and derives the pickup location address from the order's own
// shipping line item. This avoids registering a per-call (and unremovable) closure on every sync.
// See \WC_Abstract_Order::get_tax_location().
// Ensure cart is current.
if ( $update_totals ) {
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->set_payment_method( PaymentUtils::get_default_payment_method() );
$order->update_meta_data( 'is_vat_exempt', wc_bool_to_string( wc()->cart->get_customer()->get_is_vat_exempt() ) );
$order->calculate_totals();
}