Automattic\WooCommerce\StoreApi\Utilities
OrderController::sync_customer_data_with_order()
Copies order data to customer object (not the session), so values persist for future checkouts.
Method of the class: OrderController{}
No Hooks.
Return
null
. Nothing (null).
Usage
$OrderController = new OrderController(); $OrderController->sync_customer_data_with_order( $order );
- $order(\WC_Order) (required)
- Order object.
OrderController::sync_customer_data_with_order() OrderController::sync customer data with order code WC 9.7.1
public function sync_customer_data_with_order( \WC_Order $order ) { if ( $order->get_customer_id() ) { $customer = new \WC_Customer( $order->get_customer_id() ); $customer->set_props( array( 'billing_first_name' => $order->get_billing_first_name(), 'billing_last_name' => $order->get_billing_last_name(), 'billing_company' => $order->get_billing_company(), 'billing_address_1' => $order->get_billing_address_1(), 'billing_address_2' => $order->get_billing_address_2(), 'billing_city' => $order->get_billing_city(), 'billing_state' => $order->get_billing_state(), 'billing_postcode' => $order->get_billing_postcode(), 'billing_country' => $order->get_billing_country(), 'billing_email' => $order->get_billing_email(), 'billing_phone' => $order->get_billing_phone(), 'shipping_first_name' => $order->get_shipping_first_name(), 'shipping_last_name' => $order->get_shipping_last_name(), 'shipping_company' => $order->get_shipping_company(), 'shipping_address_1' => $order->get_shipping_address_1(), 'shipping_address_2' => $order->get_shipping_address_2(), 'shipping_city' => $order->get_shipping_city(), 'shipping_state' => $order->get_shipping_state(), 'shipping_postcode' => $order->get_shipping_postcode(), 'shipping_country' => $order->get_shipping_country(), 'shipping_phone' => $order->get_shipping_phone(), ) ); $this->additional_fields_controller->sync_customer_additional_fields_with_order( $order, $customer ); $customer->save(); } }