Automattic\WooCommerce\Blocks\StoreApi\Routes
Checkout::update_customer_from_request() private WC 1.0
Updates the current customer session using data from the request (e.g. address data).
Address session data is synced to the order itself later on by OrderController::update_order_from_cart()
{} Это метод класса: Checkout{}
Хуков нет.
Возвращает
Null. Ничего.
Использование
// private - только в коде основоного (родительского) класса $result = $this->update_customer_from_request( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код Checkout::update_customer_from_request() Checkout::update customer from request WC 5.0.0
private function update_customer_from_request( WP_REST_Request $request ) {
$schema = $this->get_item_schema();
$customer = wc()->customer;
if ( isset( $request['billing_address'] ) ) {
$allowed_billing_values = array_intersect_key( $request['billing_address'], $schema['properties']['billing_address']['properties'] );
foreach ( $allowed_billing_values as $key => $value ) {
if ( is_callable( [ $customer, "set_billing_$key" ] ) ) {
$customer->{"set_billing_$key"}( $value );
}
}
}
if ( isset( $request['shipping_address'] ) ) {
$allowed_shipping_values = array_intersect_key( $request['shipping_address'], $schema['properties']['shipping_address']['properties'] );
foreach ( $allowed_shipping_values as $key => $value ) {
if ( is_callable( [ $customer, "set_shipping_$key" ] ) ) {
$customer->{"set_shipping_$key"}( $value );
}
}
}
$customer->save();
}