fix(admin): shipping uses rate-level options from calculate_shipping

Removed static method-level fallback. Shipping method selector now:
1. Shows 'Enter shipping address to see available rates' when address incomplete
2. Calls calculate_shipping endpoint to get actual WC_Shipping_Rate objects
3. Displays rate-level options (e.g., JNE REG, JNE YES) not method-level

This ensures third-party shipping plugins like Rajaongkir, UPS, FedEx
display their courier rates correctly.
This commit is contained in:
Dwindi Ramadhana
2026-01-08 09:56:12 +07:00
parent 740cfcbb94
commit ab0eb3ab28

View File

@@ -1266,7 +1266,12 @@ export default function OrderForm({
{hasPhysicalProduct && (
<div>
<Label>{__('Shipping method')}</Label>
{shippingLoading ? (
{!isShippingAddressComplete ? (
/* Prompt user to enter address first */
<div className="text-sm text-muted-foreground py-2 italic">
{__('Enter shipping address to see available rates')}
</div>
) : shippingLoading ? (
<div className="text-sm text-muted-foreground py-2">{__('Calculating rates...')}</div>
) : shippingRates?.methods && shippingRates.methods.length > 0 ? (
<Select value={shippingMethod} onValueChange={setShippingMethod}>
@@ -1279,21 +1284,9 @@ export default function OrderForm({
))}
</SelectContent>
</Select>
) : isShippingAddressComplete && effectiveShippingAddress.country ? (
/* Address is complete but no methods returned - show message */
<div className="text-sm text-muted-foreground py-2">{__('No shipping methods available for this address')}</div>
) : shippings.length > 0 ? (
/* Fallback to static list when address is not complete */
<Select value={shippingMethod} onValueChange={setShippingMethod}>
<SelectTrigger className="w-full"><SelectValue placeholder={__('Select shipping')} /></SelectTrigger>
<SelectContent>
{shippings.map(s => (
<SelectItem key={s.id} value={s.id}>{s.title} {s.cost > 0 ? `- ${money(s.cost)}` : ''}</SelectItem>
))}
</SelectContent>
</Select>
) : (
<div className="text-sm text-muted-foreground py-2">{__('No shipping methods configured')}</div>
/* Address is complete but no methods returned */
<div className="text-sm text-muted-foreground py-2">{__('No shipping methods available for this address')}</div>
)}
</div>
)}