Skip to content

Instantly share code, notes, and snippets.

@riq363
riq363 / buttonDropdowns.js
Created April 17, 2019 08:16
Function to initialize buttonDropdowns in Ecwid CSS Framework
function buttonDropdowns() {
btnDropdowns = document.querySelectorAll(".btn-dropdown");
for (var i = 0; i < btnDropdowns.length; i++) {
if (btnDropdowns[i].addEventListener) {
btnDropdowns[i].addEventListener("click", function(e) {
showDropdown(this);
e.stopPropagation();
});
} else {
@riq363
riq363 / add-button-below-products-in-grid.js
Created August 1, 2018 12:30
Add button below each product in product grid
Ecwid.OnPageLoaded.add(function (page) {
// Apply changes only to category pages
if (page.type == 'CATEGORY') {
// Remove any previously added elements when new page changes
// If you change class name here, make sure to update it below too
var removingButtons = document.getElementsByClassName('custom_app_button');
for (i = removingButtons.length - 1; i >= 0; i--) {
removingButtons[i].parentNode.removeChild(removingButtons[i]);
}
// Set payment method title that matches merchant's payment method title set in Ecwid Control Panel. Use public token to get it from store profile
var paymentMethodTitle = "PayPal";
// Custom styles for icons for our application
var customStyleForPaymentIcons = document.createElement('style');
customStyleForPaymentIcons.innerHTML = ".ecwid-PaymentMethodsBlockSvgCustom { display: inline-block; width: 40px; height: 26px; background-color: #fff !important; border: 1px solid #e2e2e2 !important;}";
document.querySelector('body').appendChild(customStyleForPaymentIcons);
@riq363
riq363 / save-data-to-app-storage.js
Created February 25, 2016 11:18
Save data to application storage
var data = {
color : 'red',
size : 'big',
page_id : '123456'
};
EcwidApp.setAppStorage(data, function(){
console.log('Data saved!');
});
@riq363
riq363 / pre-order.js
Last active September 11, 2015 10:18
Add link to email to product details page. Sends SKU in the body of email and 'I want to pre-order' in the subject
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
Ecwid.OnPageLoaded.add(function(page){
setTimeout(function hidePrice() {
if(page.type == "CATEGORY") {
$(".ecwid-BuyNow-outOfStockLabel").each(function(idx, el){
$(el).after('<br/>Click to pre-order');
});
}
if (page.type == "PRODUCT") {
@riq363
riq363 / replace-0-price-with-call-for-price-text.js
Created May 29, 2015 09:01
Replace $0.00 price with 'Call for price' text
<script>
Ecwid.OnPageLoaded.add(function(page){
setTimeout(function hidePrice() {
$(".ecwid-productBrowser-price").each(function(idx, el){
if ($(el).text() == Ecwid.formatCurrency(0)) {
if(page.type == "CATEGORY") {
$(el).text('Call for price');
$('.ecwid-BuyNow-outOfStockLabel').hide();
}
else if (page.type == "PRODUCT") {
@riq363
riq363 / add product on load.js
Created May 21, 2015 14:56
Adds a product on store load
<script>
var added;
Ecwid.OnPageLoaded.add(function(Cart){
var product = {
id: 50559268,
quantity: 1,
options: {
type: "EU",
color: "Black"
}
@riq363
riq363 / cash-on-delivery-shipping-fields.js
Last active August 29, 2015 14:21
Cash on delivery script, hides shipping address fields depending on method selected
//Don't forget about jQuery!
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
if (1 || window.location.href.indexOf('key=showMeTheCheckoutMods') != -1) {
processCheckoutShippingPage = function() {
//prefill your desired data
fields = {
'address1':'Specify the address',
Ecwid.OnPageLoaded.add(function(page){
if ('ORDER_CONFIRMATION' == page.type) {
setTimeout(function(){
var order_obj = document.getElementsByClassName('ecwid-Invoice-Header-OrderNumber')[0];
var onumber= order_obj.getElementsByTagName('span')[0].textContent;
var script = document.createElement('script');
onumber = onumber.replace(/\#/g,'');
alert(onumber);
},2000);
}
@riq363
riq363 / order comments.js
Created April 15, 2015 14:34
Add placeholder for Order Comments in Ecwid
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
Ecwid.OnPageLoad.add(function(page) {
if (page.type == 'CHECKOUT_PAYMENT_DETAILS') {
$('textarea.ecwid-PaymentCommentsBlock-textarea').attr('placeholder', 'row 1\nrow2\nrow3');
}
});
</script>