Deleted by the user Autoadded Product #85
-
Hi , Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @elektro-hub // Subscribe to
document.addEventListener("liquid-ajax-cart:request-end", function(event) {
const {cart, requestState} = event.detail;
// Variant Id of the autoadded product
const variantId = 40934235668668
// Has autoadded product been just removed
const isAutoAddedItemRemoved = cart.items_removed?.find(item => item.variant_id === variantId);
if (!isAutoAddedItemRemoved) {
return false;
}
// If the product has been removed by the user action rather by a mutation
const removedByUser = requestState.info.initiator !== "mutation";
if (!removedByUser) {
return false;
}
// Save data to localStorage that the user removed the product
localStorage.setItem("autoadded_removed", "true");
});
// Also update your mutation function:
function myMutation() {
// Right in the beginning stop the mutation function if the user has localStorage value
if (localStorage.getItem("autoadded_removed") === "true") {
return;
}
... |
Beta Was this translation helpful? Give feedback.
Hi @elektro-hub
Yes, you can subscribe to the
liquid-ajax-cart:request-end
event, check if the autoadded item has been just removed removed using thecart
property of the event and add cookie or a localStorage value to the user that will indicate that they don't wanna have the autoadded item: