-
-
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
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
<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