Skip to content

Commit 4736991

Browse files
committed
Clear the cart if quantity is 0
1 parent 1353d9e commit 4736991

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

components/Cart/CartPage/CartItemsContainer.component.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const CartItemsContainer = () => {
3232
},
3333
] = useMutation(UPDATE_CART, {
3434
onCompleted: () => {
35+
36+
3537
refetch();
3638
},
3739
onError: (error) => {
@@ -64,12 +66,19 @@ const CartItemsContainer = () => {
6466
},
6567
},
6668
});
69+
70+
// Clear out the cart in localStorage and the cart to null
71+
if(updatedItems[0].quantity === 0 && process.browser) {
72+
setCart(null)
73+
localStorage.removeItem('woocommerce-cart')
74+
localStorage.removeItem('woo-session')
75+
}
6776
}
6877
};
6978

7079
const { loading, error, data, refetch } = useQuery(GET_CART, {
7180
onCompleted: () => {
72-
// Update cart in the localStorage.
81+
// Update cart in the localStorage.
7382
const updatedCart = getFormattedCart(data);
7483
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
7584
// Update cart data in React Context.
@@ -80,7 +89,7 @@ const CartItemsContainer = () => {
8089
setRequestError(error);
8190
},
8291
});
83-
// TODO Add more functionality
92+
8493

8594
return (
8695
<>

components/Checkout/Billing.component.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const Billing = ({ input, handleOnChange }) => {
108108
name="paymentMethod"
109109
type="radio"
110110
checked
111+
readOnly
111112
/>
112113
</div>
113114
<div className="w-full p-2">

0 commit comments

Comments
 (0)