Skip to main content

Requiring shoppers to log in before they can use the Wishlist

This customization enforces a login requirement before a user can add a product to their wishlist, and before they can access it.

Updated over 2 months ago

Navigate to your theme and click Actions > Edit code

Add a new file called swym-custom.liquid in the Snippets folder.

This file will contain the code for the login page redirect.

Paste the code below into the newly created swym-custom.liquid file.

<script defer>
document.addEventListener('DOMContentLoaded', () => {
var isLoggedIn;
{% if customer %}
isLoggedIn = true;
{% else %}
isLoggedIn = false;
{% endif %}

const swymRedirectToLogin = () => {
setTimeout(() => {
window.location.href = "/account/login";
}, 100);
};

function swymCallbackFn(swat) {
if (!isLoggedIn) {
swat.ui.open = swymRedirectToLogin;
swat.api.addToWishList = swymRedirectToLogin;
swat.ui.uiRef.addToWishlist = swymRedirectToLogin;
swat.addProductToLists = swymRedirectToLogin;
swat.removeProductFromLists = swymRedirectToLogin;

if (window._swat) {
window._swat.addToList = swymRedirectToLogin;
window._swat.deleteFromList = swymRedirectToLogin;
}

if (window.SwymUtils && window.SwymUtils.getHostedURL) {
window.SwymUtils.getHostedURL = () => "/account/login";
}

if (window.SwymStorefrontLayoutExtensions?.SwymStorefrontLayoutPageActions) {
window.SwymStorefrontLayoutExtensions.SwymStorefrontLayoutPageActions.setData = swymRedirectToLogin;
window.SwymStorefrontLayoutExtensions.SwymStorefrontLayoutPageActions.openDrawer = swymRedirectToLogin;
}
}
}

if (!window.SwymCallbacks) {
window.SwymCallbacks = [];
}
window.SwymCallbacks.push(swymCallbackFn);
});
</script>

Include the file swym-custom.liquid to your theme.liquid

We'd recommend including the file right before the end of the closing </body> tag, using the code below:

{% render 'swym-custom' %}

Need further assistance?

You can always reach out to us at [email protected].

If you're already on our messenger, simply say "talk to an agent," and Fin will connect you with a member of our team who can provide further assistance.

Did this answer your question?