Skip to content

Commit eae084c

Browse files
committed
Clear cart on order success
1 parent e079b21 commit eae084c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pages/success.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
</template>
77

88
<script setup>
9+
import { useCart } from "@/store/useCart";
10+
11+
const cart = useCart();
12+
13+
onBeforeMount(() => {
14+
cart.clearCart();
15+
});
16+
917
useHead({
1018
title: "Order placed",
1119
titleTemplate: "%s - Nuxt 3 Woocommerce",

store/useCart.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ export const useCart = defineStore("cartState", {
2424
removeProductFromCart(product) {
2525
this.cart.splice(this.cart.indexOf(product), 1);
2626
},
27-
2827
clearCart() {
29-
console.log("Called clear cart action");
30-
this.cart = [];
31-
//this.cart.length = 0;
32-
console.log("Length: ", this.cart.length);
28+
this.cart.length = 0;
3329
},
3430
},
3531
getters: {

0 commit comments

Comments
 (0)