Skip to content

Instantly share code, notes, and snippets.

@riq363
Forked from makfruit/ecwid-cash-on-delivery.js
Last active December 2, 2016 15:47
Show Gist options
  • Save riq363/40e8fa28d21f3b647ed6 to your computer and use it in GitHub Desktop.
Save riq363/40e8fa28d21f3b647ed6 to your computer and use it in GitHub Desktop.
Hide or show payment methods in Ecwid depending on the delivery methods selected
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
Ecwid.paymentOptionElement = function(caption) {
return jQuery("label:contains('" + caption + "')").parents('.ecwid-PaymentMethodsBlock-PaymentOption');
};
Ecwid.OnPageLoaded.add(function(page) {
if (page.type === 'CHECKOUT_PAYMENT_DETAILS') {
Ecwid.Cart.get(function(cart) {
//if customer selects 'Local delivery' shipping method
if (cart.shippingMethod === 'Local delivery') {
//then hide 'PayPal Express Checkout' and 'Credit card' payment method
Ecwid.paymentOptionElement('PayPal Express Checkout').hide();
Ecwid.paymentOptionElement('Credit card').hide();
} else {
//if customer selects any other shipping method, hide 'Cash on delivery' payment method
Ecwid.paymentOptionElement('Cash on delivery').hide();
}
if (jQuery('.ecwid-PaymentMethodsBlock-PaymentOption:visible input:checked').length === 0) {
jQuery('.ecwid-PaymentMethodsBlock-PaymentOption:visible:first input')[0].click();
}
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment