WC_REST_Paypal_Standard_Controller::update_order_shipping_addressprivateWC 1.0

Update the WooCommerce order with the new shipping address.

Метод класса: WC_REST_Paypal_Standard_Controller{}

Хуков нет.

Возвращает

void. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->update_order_shipping_address( $order, $shipping_address );
$order(WC_Order) (обязательный)
The order object.
$shipping_address(массив) (обязательный)
The shipping address.

Код WC_REST_Paypal_Standard_Controller::update_order_shipping_address() WC 11.1.0

private function update_order_shipping_address( $order, $shipping_address ) {
	$country  = $shipping_address['country_code'] ?? '';
	$postcode = $shipping_address['postal_code'] ?? '';
	$state    = $shipping_address['admin_area_1'] ?? '';
	$city     = $shipping_address['admin_area_2'] ?? '';

	$order->set_shipping_country( $country );
	$order->set_shipping_postcode( $postcode );
	$order->set_shipping_state( $state );
	$order->set_shipping_city( $city );

	// We do not have the address line 1 and 2 -- we are clearing them here to avoid
	// showing stale data. The final address will be updated when the
	// customer approves the order, via 'woocommerce_thankyou_paypal' hook.
	$order->set_shipping_address_1( '' );
	$order->set_shipping_address_2( '' );
	$order->save();

	// Get customer from order and update their shipping location.
	$customer = new WC_Customer();
	$customer->set_location( $country, $state, $postcode, $city );
	$customer->set_shipping_location( $country, $state, $postcode, $city );
	$customer->set_calculated_shipping( true );
	WC()->customer = $customer;
}