WordPress.org

Support

Support » Plugins and Hacks » Jigoshop » How to select a payment option based on country

How to select a payment option based on country

  • Here’s a suggestion for anyone looking to be able to change the options viewable at checkout based on country. Place in theme’s functions.php (so doesn’t get lost when upgrade jigoshop) and modify code as required.

    function autoSelectAtCheckout() {
    		?>
    		<script>
    		jQuery(document).ready(function($){
    			function changeMexico() {
    				$('#payment_method_bank_transfer').prop('checked',true);
    				$('#payment_method_paypal').show();
    				$('#payment_method_paypal').next('label').show();
    				$('#payment_method_bank_transfer').show();
    				$('#payment_method_bank_transfer').next('label').show();
    				$('#payment_method_cod').hide();
    				$('#payment_method_cod').next('label').hide();
    			}
    			function changeUS() {
    				$('#payment_method_paypal').prop('checked',true);
    				$('#payment_method_paypal').show();
    				$('#payment_method_paypal').next('label').show();
    				$('#payment_method_bank_transfer').hide();
    				$('#payment_method_bank_transfer').next('label').hide();
    				$('#payment_method_cod').hide();
    				$('#payment_method_cod').next('label').hide();
    			}
    			function changeOther() {
    				$('#payment_method_cod').prop('checked',true);
    				$('#payment_method_paypal').hide();
    				$('#payment_method_paypal').next('label').hide();
    				$('#payment_method_bank_transfer').hide();
    				$('#payment_method_bank_transfer').next('label').hide();
    				$('#payment_method_cod').show();
    				$('#payment_method_cod').next('label').show();
    			}
    
    			function changeOptions() {
    				if ($('#billing_country').val() == 'AD') {
    					changeOther();
    				}
    				else if ($('#billing_country').val() == 'US') {
    					changeUS();
    				}
    				else if ($('#billing_country').val() == 'MX') {
    					changeMexico();
    				}
    			}
    			changeOptions();
    			$('#billing_country').change(changeOptions);
    		});
    		</script>
    		<?php
    	}
    	add_action ('before_checkout_form','autoSelectAtCheckout',25);

    https://wordpress.org/plugins/jigoshop/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to select a payment option based on country’ is closed to new replies.
Skip to toolbar