A drop-in HTML/JS script for Ecwid to force logout after an order is placed
<script type="text/javascript"> | |
// A drop-in HTML/JS script for Ecwid to force logout after an order is placed | |
if (typeof(Ecwid) == 'object') { | |
Ecwid.OnPageLoaded.add(function(page) { | |
if ('ORDER_CONFIRMATION' == page.type) { | |
var localStoragePrefix = 'PSecwid__' + Ecwid.getOwnerId() + 'PS'; | |
var isLoggedIn = (localStorage.getItem(localStoragePrefix + 'token') != null); | |
if (isLoggedIn) { | |
var itemsToRemove = ['token','customerid','profile']; | |
for (var i = 0; i < itemsToRemove.length; i++) { | |
localStorage.removeItem(localStoragePrefix + itemsToRemove[i]); | |
} | |
window.location.reload(true); | |
} | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Hi,
Is there any way this code could also clear the cart?
I have a client running Ecwid in a shop kiosk.
I use this code to sign out and start a new session every time the home page is loaded, and need to clear the cart/basket too if possible.
EDIT - I figured out how to do this. Here is a modified version that also clears the cart regardless of the user being signed in:
Thanks,
Ian