Last active
August 29, 2015 14:21
-
-
Save riq363/da432530a9dee4a6ee4c to your computer and use it in GitHub Desktop.
Cash on delivery script, hides shipping address fields depending on method selected
This file contains 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
//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', | |
'address2': '', | |
'city': 'Name of the city', | |
'state': 'Value for state', | |
'country': 'Value for country', | |
'zip': 'Zip code' | |
}; | |
for (var i in fields) { | |
jQuery('.ecwid-AddressForm-' + i) | |
.closest('.ecwid-fieldWrapper') | |
.find('input,select').val(fields[i]); | |
} | |
return true; | |
}; | |
$(document).ready(function() { | |
tickers = {}; | |
Ecwid.OnPageLoaded.add(function(page) { | |
for (var i in tickers) { | |
if (tickers[i]) { | |
clearInterval(tickers[i]); | |
tickers[i] = false; | |
} | |
} | |
switch(page.type) { | |
//if the page is Shipping address | |
case 'CHECKOUT_SHIPPING_ADDRESS': | |
tickers[page.type] = setInterval(processCheckoutShippingPage, 500); | |
Ecwid.OnCartChanged.add(function(cart){ | |
// if cash on delivery method selected | |
if (cart.shippingMethod == 'Cash on delivery') { | |
//hide fields and prefill them with data | |
processCheckoutShippingPage(); | |
$('#my-store-STOREID').addClass('ecwid-mod'); | |
} | |
else { | |
// if shipping required, show address fields | |
$('#my-store-STOREID').removeClass('ecwid-mod'); | |
} | |
}); | |
break; | |
//if page is payment details | |
case 'CHECKOUT_PAYMENT_DETAILS': | |
Ecwid.OnCartChanged.add(function(cart){ | |
// if cash on delivery method selected | |
if (cart.shippingMethod == 'Cash on delivery') { | |
// apply CSS and prefill email block | |
$('#my-store-STOREID').addClass('ecwid-mod'); | |
processPaymentDetailsPage(); | |
} | |
else { | |
// if shipping required, do nothing | |
$('#my-store-STOREID').removeClass('ecwid-mod'); | |
} | |
}); | |
break; | |
} | |
}); | |
processPaymentDetailsPage = function() { | |
$('.ecwid-Checkout-EmailBlock input[name="email"]').val('Your desired email'); | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment