feat(checkout): fix searchable select API search and add billing destination

Fixes:
1. SearchableSelect now supports onSearch prop for API-based search
   - Added onSearch and isSearching props
   - shouldFilter disabled when onSearch provided
2. DynamicCheckoutField connects handleApiSearch to SearchableSelect
3. RAJAONGKIR_INTEGRATION.md adds both billing and shipping destination_id

This enables the destination search field to actually call the API
when user types, instead of just filtering local (empty) options.
This commit is contained in:
Dwindi Ramadhana
2026-01-08 14:47:54 +07:00
parent f6b778c7fc
commit f518d7e589
3 changed files with 40 additions and 9 deletions

View File

@@ -88,7 +88,7 @@ function woonoow_rajaongkir_search_destinations($request) {
}
// ============================================================
// 2. Add destination field to checkout fields
// 2. Add destination field to checkout fields (both billing and shipping)
// Always add for Indonesia zone (no premature country check)
// ============================================================
add_filter('woocommerce_checkout_fields', function($fields) {
@@ -103,12 +103,11 @@ add_filter('woocommerce_checkout_fields', function($fields) {
return $fields;
}
// Add searchable destination field
// The frontend will show/hide based on selected country
$fields['shipping']['shipping_destination_id'] = [
// Destination field definition (reused for billing and shipping)
$destination_field = [
'type' => 'searchable_select',
'label' => __('Destination (Province, City, Subdistrict)', 'woonoow'),
'required' => false, // Not required initially, SPA will manage this
'required' => false, // Frontend will manage this based on country
'priority' => 85,
'class' => ['form-row-wide'],
'placeholder' => __('Search destination...', 'woonoow'),
@@ -122,6 +121,12 @@ add_filter('woocommerce_checkout_fields', function($fields) {
],
];
// Add to billing (used when "Ship to different address" is NOT checked)
$fields['billing']['billing_destination_id'] = $destination_field;
// Add to shipping (used when "Ship to different address" IS checked)
$fields['shipping']['shipping_destination_id'] = $destination_field;
return $fields;
}, 20); // Priority 20 to run after Rajaongkir's own filter