@@ -8,6 +8,20 @@ export function useCheckout() {
8
8
const { storeSettings } = useAppConfig ( ) ;
9
9
const errorMessage = useState < string | null > ( 'errorMessage' , ( ) => null ) ;
10
10
const orderInput = useState < any > ( 'orderInput' , ( ) => {
11
+
12
+ if ( ! import . meta. env . SSR ) {
13
+ try {
14
+ // Try to load saved order input from localStorage
15
+ const savedOrderInput = localStorage . getItem ( 'WooNuxtOrderInput' ) ;
16
+ if ( savedOrderInput ) {
17
+ return JSON . parse ( savedOrderInput ) ;
18
+ }
19
+ } catch ( error ) {
20
+ localStorage . removeItem ( 'WooNuxtOrderInput' ) ;
21
+ console . error ( 'Failed to load order input from localStorage:' , error ) ;
22
+ }
23
+ }
24
+
11
25
return {
12
26
customerNote : '' ,
13
27
paymentMethod : '' ,
@@ -16,13 +30,6 @@ export function useCheckout() {
16
30
} ;
17
31
} ) ;
18
32
19
- onMounted ( ( ) => {
20
- const savedOrderInput = localStorage . getItem ( 'WooNuxtOrderInput' ) ;
21
- if ( savedOrderInput ) {
22
- orderInput . value = JSON . parse ( savedOrderInput ) ;
23
- }
24
- } ) ;
25
-
26
33
const isProcessingOrder = useState < boolean > ( 'isProcessingOrder' , ( ) => false ) ;
27
34
28
35
// if Country or State are changed, calculate the shipping rates again
@@ -175,9 +182,9 @@ export function useCheckout() {
175
182
if ( error ) {
176
183
throw new CheckoutInlineError ( error . message ) ;
177
184
}
178
-
185
+
179
186
const { source } = await stripe . createSource ( cardElement as CreateSourceData ) ;
180
-
187
+
181
188
if ( source ) orderInput . value . metaData . push ( { key : '_stripe_source_id' , value : source . id } ) ;
182
189
if ( setupIntent ) orderInput . value . metaData . push ( { key : '_stripe_intent_id' , value : setupIntent . id } ) ;
183
190
@@ -251,7 +258,7 @@ export function useCheckout() {
251
258
252
259
useRouter ( ) . push ( { query : { } } ) ;
253
260
manageCheckoutLocalStorage ( false ) ;
254
-
261
+
255
262
if ( error instanceof CheckoutInlineError ) {
256
263
errorMessage . value = error . message ;
257
264
} else {
0 commit comments