feat: implement multiple saved addresses with modal selector in checkout
- Add AddressController with full CRUD API for saved addresses - Implement address management UI in My Account > Addresses - Add modal-based address selector in checkout (Tokopedia-style) - Hide checkout forms when saved address is selected - Add search functionality in address modal - Auto-select default addresses on page load - Fix variable products to show 'Select Options' instead of 'Add to Cart' - Add admin toggle for multiple addresses feature - Clean up debug logs and fix TypeScript errors
This commit is contained in:
@@ -79,19 +79,7 @@ class AccountController {
|
||||
],
|
||||
]);
|
||||
|
||||
// Get addresses
|
||||
register_rest_route($namespace, '/account/addresses', [
|
||||
[
|
||||
'methods' => 'GET',
|
||||
'callback' => [__CLASS__, 'get_addresses'],
|
||||
'permission_callback' => [__CLASS__, 'check_customer_permission'],
|
||||
],
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [__CLASS__, 'update_addresses'],
|
||||
'permission_callback' => [__CLASS__, 'check_customer_permission'],
|
||||
],
|
||||
]);
|
||||
// Address routes moved to AddressController
|
||||
|
||||
// Get downloads (for digital products)
|
||||
register_rest_route($namespace, '/account/downloads', [
|
||||
@@ -330,34 +318,51 @@ class AccountController {
|
||||
* Format order data for API response
|
||||
*/
|
||||
private static function format_order($order, $detailed = false) {
|
||||
$payment_title = $order->get_payment_method_title();
|
||||
if (empty($payment_title)) {
|
||||
$payment_title = $order->get_payment_method() ?: 'Not specified';
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => $order->get_id(),
|
||||
'order_number' => $order->get_order_number(),
|
||||
'status' => $order->get_status(),
|
||||
'date_created' => $order->get_date_created()->date('Y-m-d H:i:s'),
|
||||
'total' => $order->get_total(),
|
||||
'date' => $order->get_date_created()->date('Y-m-d H:i:s'),
|
||||
'total' => html_entity_decode(strip_tags(wc_price($order->get_total()))),
|
||||
'currency' => $order->get_currency(),
|
||||
'payment_method' => $order->get_payment_method_title(),
|
||||
'payment_method_title' => $payment_title,
|
||||
];
|
||||
|
||||
if ($detailed) {
|
||||
$data['items'] = array_map(function($item) {
|
||||
$items = $order->get_items();
|
||||
$data['items'] = is_array($items) ? array_values(array_map(function($item) {
|
||||
$product = $item->get_product();
|
||||
return [
|
||||
'id' => $item->get_id(),
|
||||
'name' => $item->get_name(),
|
||||
'quantity' => $item->get_quantity(),
|
||||
'total' => $item->get_total(),
|
||||
'total' => html_entity_decode(strip_tags(wc_price($item->get_total()))),
|
||||
'image' => $product ? wp_get_attachment_url($product->get_image_id()) : '',
|
||||
];
|
||||
}, $order->get_items());
|
||||
}, $items)) : [];
|
||||
|
||||
// Check if order needs shipping (not virtual-only)
|
||||
$needs_shipping = false;
|
||||
foreach ($order->get_items() as $item) {
|
||||
$product = $item->get_product();
|
||||
if ($product && !$product->is_virtual()) {
|
||||
$needs_shipping = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$data['billing'] = $order->get_address('billing');
|
||||
$data['shipping'] = $order->get_address('shipping');
|
||||
$data['subtotal'] = $order->get_subtotal();
|
||||
$data['shipping_total'] = $order->get_shipping_total();
|
||||
$data['tax_total'] = $order->get_total_tax();
|
||||
$data['discount_total'] = $order->get_discount_total();
|
||||
$data['needs_shipping'] = $needs_shipping;
|
||||
$data['subtotal'] = html_entity_decode(strip_tags(wc_price($order->get_subtotal())));
|
||||
$data['shipping_total'] = html_entity_decode(strip_tags(wc_price($order->get_shipping_total())));
|
||||
$data['tax_total'] = html_entity_decode(strip_tags(wc_price($order->get_total_tax())));
|
||||
$data['discount_total'] = html_entity_decode(strip_tags(wc_price($order->get_discount_total())));
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
Reference in New Issue
Block a user