Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save j26design/304e94ba6fc7a73f0c6b to your computer and use it in GitHub Desktop.
Save j26design/304e94ba6fc7a73f0c6b to your computer and use it in GitHub Desktop.
An HTML/Javascript code snippet for Ecwid to redirect continue shopping buttons to a custom page
if (typeof(Ecwid) == 'object') {
Ecwid.OnAPILoaded.add(function() {
// Redirect address. Change it to the URL of page where you want to redirect your customers.
// You can use absolute or relative addresses, e.g. 'index.html', 'http://google.com'
var continueShoppingRedirect = "#!/~/category/id=0";
// Delay (ms), which is necessary for the empty cart page to appear after onCartChange event firing
var empty_cart_page_delay = 500;
// Continue shopping buttons CSS selectors
// (you can remove the ones that you don't want to change behavior for)
var buttons = [
'div.ecwid-productBrowser-details button.ecwid-btn.ecwid-btn--primary.ecwid-btn--continueShopping', // Product details
'div.ecwid-productBrowser-cart button.ecwid-btn.ecwid-btn--secondary.ecwid-btn--continueShopping', // Cart page
'div.ecwid-productBrowser-cart-emptyCartPanel button.ecwid-btn.ecwid-btn--secondary.ecwid-btn--continueShopping', // Empty cart page
'div.ecwid-Invoice-buttons-panel button.ecwid-btn.ecwid-btn--secondary.ecwid-btn--continueShopping', // Order confirmation page
'div.ecwid-productBrowser-search-ContinueShoppingButtonContainer button.ecwid-btn.ecwid-btn--secondary.ecwid-btn--continueShopping', // Search results page
'div.ecwid-Account-ContinueShoppingButtonContainer button.ecwid-btn.ecwid-btn--secondary.ecwid-btn--continueShopping' // 'My account' pages
];
// Pages (Ecwid.Page.type) where buttons should be customized
// (you can remove the pages that you don't want to change the buttons on)
var pages = [
'CART',
'SEARCH',
'ORDER_CONFIRMATION',
'ACCOUNT_SETTINGS',
'ORDERS',
'ADDRESS_BOOK'
];
// This function find the continue shoppign button on the page and replace it with a customized one
var replaceButton = function() {
var buttonObject = jQuery(buttons.join()).filter(":not('.clone'):visible");
if (buttonObject.length) {
buttonObject.clone().addClass('clone').appendTo(buttonObject.parent()).click(function() {
location.href = continueShoppingRedirect;
});
// Remove the original button
buttonObject.remove();
}
}
// Replace the button on page loading
Ecwid.OnPageLoaded.add(function(page) {
if (jQuery.inArray(page.type, pages) >= 0) {
replaceButton();
}
});
// Replace the button on the empty cart page after clearing the cart
// (it doesn't fire onPageLoaded event)
Ecwid.OnCartChanged.add(function(page) {
setTimeout(replaceButton, empty_cart_page_delay);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment