← All changes
|
app/Hooks/Handlers/ShortCodes/Checkout/CheckoutPageHandler.php
+17
-0
1.3.21
→
1.7.0
View file →
| @@ -40,8 +40,17 @@ | ||
| 40 | 40 | // this is a new cart. So we should fill the address id if any |
| 41 | 41 | $primaryBillingAddress = $currentCustomer->primary_billing_address; |
| 42 | 42 | if ($primaryBillingAddress) { |
| 43 | 43 | $formData['billing_address_id'] = $primaryBillingAddress->id; |
| 44 | + } else { | |
| 45 | + // Case 3: no primary address — use the first available billing address | |
| 46 | + $firstBillingAddress = $currentCustomer->billing_address() | |
| 47 | + ->where('status', 'active') | |
| 48 | + ->orderBy('id', 'ASC') | |
| 49 | + ->first(); | |
| 50 | + if ($firstBillingAddress) { | |
| 51 | + $formData['billing_address_id'] = $firstBillingAddress->id; | |
| 52 | + } | |
| 44 | 53 | } |
| 45 | 54 | |
| 46 | 55 | if ($cart->isShipToDifferent()) { |
| 47 | 56 | $primaryShippingAddress = $currentCustomer->primary_shipping_address; |
| @@ -46,8 +55,16 @@ | ||
| 46 | 55 | if ($cart->isShipToDifferent()) { |
| 47 | 56 | $primaryShippingAddress = $currentCustomer->primary_shipping_address; |
| 48 | 57 | if ($primaryShippingAddress) { |
| 49 | 58 | $formData['shipping_address_id'] = $primaryShippingAddress->id; |
| 59 | + } else { | |
| 60 | + $firstShippingAddress = $currentCustomer->shipping_address() | |
| 61 | + ->where('status', 'active') | |
| 62 | + ->orderBy('id', 'ASC') | |
| 63 | + ->first(); | |
| 64 | + if ($firstShippingAddress) { | |
| 65 | + $formData['shipping_address_id'] = $firstShippingAddress->id; | |
| 66 | + } | |
| 50 | 67 | } |
| 51 | 68 | } |
| 52 | 69 | } |
| 53 | 70 | |