Open aaronbentley opened 3 years ago
Same use case here. @AaronBentley have you found a way to prgrammatically delete all favourites for a user?
Hey @w3b-beweb,
Apologies for the late reply, it's been a crazy few days in the world πΊπ¦.
I did find a way to accomplish this, it's not particularly pretty however it does accomplish what I was trying to do. Essentially I managed to mimic the behaviour of the built-in Clear Favourites button via custom javascript.
You need to have the built-in 'Clear Favourites' button on the page you wish to add this functionality to using this function call in your template:
the_clear_favorites_button();
Then simulate the click event, here's how I did it via jQuery:
// Get reference to the 'Clear favourites" button
const clearFavouritesButton = $( 'button.simplefavorites-clear' )
// Trigger an artificial click event to mimic the behaviour of a user clicking the Clear Favourites button
clearFavouritesButton.trigger( 'click' )
i imagine you would need to have this fire on a different event(such as a form submission event or similar).
If you want to see this implementation in practice:
In this instance, the custom clear favourites javascript is fired when a user successfully submits the 'Email Your Favourites' form.
Hope this helps my friend π
Hello, thanks for your work on this plugin, it's been super helpful for my latest project.
I am using this plugin to allow users to select favourites (anonymously), then submit their favourites via a form, I'd like to clear out the selected favourites once the form submission is complete.
Is there a way to do this pragmatically?
KR,
Aaron.