WC_REST_Paypal_Standard_Controller::update_order_shipping_addressprivateWC 1.0

Update the WooCommerce order with the new shipping address.

Method of the class: WC_REST_Paypal_Standard_Controller{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->update_order_shipping_address( $order, $shipping_address );
$order(WC_Order) (required)
The order object.
$shipping_address(array) (required)
The shipping address.

WC_REST_Paypal_Standard_Controller::update_order_shipping_address() code WC 10.3.6

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;
}