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.
Метод класса: OrderController{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$OrderController = new OrderController(); $OrderController->sync_customer_data_with_order( $order );
- $order(\WC_Order) (обязательный)
- Order object.
Код OrderController::sync_customer_data_with_order() OrderController::sync customer data with order WC 8.7.0
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(), ) ); $order_fields = $this->additional_fields_controller->get_all_fields_from_order( $order ); $customer_fields = $this->additional_fields_controller->filter_fields_for_customer( $order_fields ); foreach ( $customer_fields as $key => $value ) { $this->additional_fields_controller->persist_field_for_customer( $key, $value, $customer ); } $customer->save(); }; }