Skip to content

Commit

Permalink
Clear cart on order success
Browse files Browse the repository at this point in the history
  • Loading branch information
w3bdesign committed Feb 5, 2023
1 parent e079b21 commit eae084c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 8 additions & 0 deletions pages/success.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
</template>

<script setup>
import { useCart } from "@/store/useCart";
const cart = useCart();
onBeforeMount(() => {
cart.clearCart();
});
useHead({
title: "Order placed",
titleTemplate: "%s - Nuxt 3 Woocommerce",
Expand Down
6 changes: 1 addition & 5 deletions store/useCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ export const useCart = defineStore("cartState", {
removeProductFromCart(product) {
this.cart.splice(this.cart.indexOf(product), 1);
},

clearCart() {
console.log("Called clear cart action");
this.cart = [];
//this.cart.length = 0;
console.log("Length: ", this.cart.length);
this.cart.length = 0;
},
},
getters: {
Expand Down

0 comments on commit eae084c

Please sign in to comment.