Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Removes legacy shipping_phone handling (#5326)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley authored Dec 8, 2021
1 parent 8ef356f commit de2dd8e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 53 deletions.
59 changes: 22 additions & 37 deletions src/StoreApi/Routes/CartUpdateCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,30 @@ protected function get_route_post_response( \WP_REST_Request $request ) {
}
wc()->customer->set_props(
array(
'billing_first_name' => isset( $billing['first_name'] ) ? $billing['first_name'] : null,
'billing_last_name' => isset( $billing['last_name'] ) ? $billing['last_name'] : null,
'billing_company' => isset( $billing['company'] ) ? $billing['company'] : null,
'billing_address_1' => isset( $billing['address_1'] ) ? $billing['address_1'] : null,
'billing_address_2' => isset( $billing['address_2'] ) ? $billing['address_2'] : null,
'billing_city' => isset( $billing['city'] ) ? $billing['city'] : null,
'billing_state' => isset( $billing['state'] ) ? $billing['state'] : null,
'billing_postcode' => isset( $billing['postcode'] ) ? $billing['postcode'] : null,
'billing_country' => isset( $billing['country'] ) ? $billing['country'] : null,
'billing_phone' => isset( $billing['phone'] ) ? $billing['phone'] : null,
'billing_email' => isset( $request['billing_address'], $request['billing_address']['email'] ) ? $request['billing_address']['email'] : null,
'shipping_first_name' => isset( $shipping['first_name'] ) ? $shipping['first_name'] : null,
'shipping_last_name' => isset( $shipping['last_name'] ) ? $shipping['last_name'] : null,
'shipping_company' => isset( $shipping['company'] ) ? $shipping['company'] : null,
'shipping_address_1' => isset( $shipping['address_1'] ) ? $shipping['address_1'] : null,
'shipping_address_2' => isset( $shipping['address_2'] ) ? $shipping['address_2'] : null,
'shipping_city' => isset( $shipping['city'] ) ? $shipping['city'] : null,
'shipping_state' => isset( $shipping['state'] ) ? $shipping['state'] : null,
'shipping_postcode' => isset( $shipping['postcode'] ) ? $shipping['postcode'] : null,
'shipping_country' => isset( $shipping['country'] ) ? $shipping['country'] : null,
'billing_first_name' => $billing['first_name'] ?? null,
'billing_last_name' => $billing['last_name'] ?? null,
'billing_company' => $billing['company'] ?? null,
'billing_address_1' => $billing['address_1'] ?? null,
'billing_address_2' => $billing['address_2'] ?? null,
'billing_city' => $billing['city'] ?? null,
'billing_state' => $billing['state'] ?? null,
'billing_postcode' => $billing['postcode'] ?? null,
'billing_country' => $billing['country'] ?? null,
'billing_phone' => $billing['phone'] ?? null,
'billing_email' => $billing['email'] ?? null,
'shipping_first_name' => $shipping['first_name'] ?? null,
'shipping_last_name' => $shipping['last_name'] ?? null,
'shipping_company' => $shipping['company'] ?? null,
'shipping_address_1' => $shipping['address_1'] ?? null,
'shipping_address_2' => $shipping['address_2'] ?? null,
'shipping_city' => $shipping['city'] ?? null,
'shipping_state' => $shipping['state'] ?? null,
'shipping_postcode' => $shipping['postcode'] ?? null,
'shipping_country' => $shipping['country'] ?? null,
'shipping_phone' => $shipping['phone'] ?? null,
)
);

$shipping_phone_value = isset( $shipping['phone'] ) ? $shipping['phone'] : null;

// @todo Remove custom shipping_phone handling (requires WC 5.6+)
if ( is_callable( [ wc()->customer, 'set_shipping_phone' ] ) ) {
wc()->customer->set_shipping_phone( $shipping_phone_value );
} else {
wc()->customer->update_meta_data( 'shipping_phone', $shipping_phone_value );
}

wc()->customer->save();

$this->calculate_totals();
Expand Down Expand Up @@ -170,17 +162,10 @@ protected function maybe_update_order() {
'shipping_state' => wc()->customer->get_shipping_state(),
'shipping_postcode' => wc()->customer->get_shipping_postcode(),
'shipping_country' => wc()->customer->get_shipping_country(),
'shipping_phone' => wc()->customer->get_shipping_phone(),
]
);

$shipping_phone_value = is_callable( [ wc()->customer, 'get_shipping_phone' ] ) ? wc()->customer->get_shipping_phone() : wc()->customer->get_meta( 'shipping_phone', true );

if ( is_callable( [ $draft_order, 'set_shipping_phone' ] ) ) {
$draft_order->set_shipping_phone( $shipping_phone_value );
} else {
$draft_order->update_meta_data( '_shipping_phone', $shipping_phone_value );
}

$draft_order->save();
}
}
10 changes: 2 additions & 8 deletions src/StoreApi/Schemas/ShippingAddressSchema.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;

use Automattic\WooCommerce\Blocks\RestApi\Routes;
use Automattic\WooCommerce\Blocks\StoreApi\Routes\RouteException;

/**
* ShippingAddressSchema class.
Expand Down Expand Up @@ -36,12 +36,6 @@ class ShippingAddressSchema extends AbstractAddressSchema {
*/
public function get_item_response( $address ) {
if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
if ( is_callable( [ $address, 'get_shipping_phone' ] ) ) {
$shipping_phone = $address->get_shipping_phone();
} else {
$shipping_phone = $address->get_meta( $address instanceof \WC_Customer ? 'shipping_phone' : '_shipping_phone', true );
}

$shipping_country = $address->get_shipping_country();
$shipping_state = $address->get_shipping_state();

Expand All @@ -60,7 +54,7 @@ public function get_item_response( $address ) {
'state' => $shipping_state,
'postcode' => $address->get_shipping_postcode(),
'country' => $shipping_country,
'phone' => $shipping_phone,
'phone' => $address->get_shipping_phone(),
]
);
}
Expand Down
9 changes: 1 addition & 8 deletions src/StoreApi/Utilities/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,10 @@ public function sync_customer_data_with_order( \WC_Order $order ) {
'shipping_state' => $order->get_shipping_state(),
'shipping_postcode' => $order->get_shipping_postcode(),
'shipping_country' => $order->get_shipping_country(),
'shipping_phone' => $order->get_shipping_phone(),
]
);

$shipping_phone_value = is_callable( [ $order, 'get_shipping_phone' ] ) ? $order->get_shipping_phone() : $order->get_meta( '_shipping_phone', true );

if ( is_callable( [ $customer, 'set_shipping_phone' ] ) ) {
$customer->set_shipping_phone( $shipping_phone_value );
} else {
$customer->update_meta_data( 'shipping_phone', $shipping_phone_value );
}

$customer->save();
};
}
Expand Down

0 comments on commit de2dd8e

Please sign in to comment.