Last active
April 25, 2021 20:48
-
-
Save makfruit/5708347 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- An HTML/Javascript code snippet for Ecwid to redirect continue shopping buttons to a custom page --> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<script> | |
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 = [ | |
'button.ecwid-productBrowser-cart-continueShoppingButton', // Cart page | |
'div.ecwid-productBrowser-cart-emptyCartPanel button.gwt-Button', // Empty cart page | |
'button.ecwid-ContinueShoppingButton-Invoice', // Order confirmation page | |
'div.ecwid-productBrowser-search-ContinueShoppingButtonContainer button.gwt-Button', // Search results page | |
'div.ecwid-Account-ContinueShoppingButtonContainer button.gwt-Button' // '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); | |
}); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment