WordPress.org

Forums

Jigoshop
How to select a payment option based on country (3 posts)

  1. nbruley
    Member
    Posted 2 years ago #

    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/

  2. Jigoshop Support - Marcin
    Member
    Posted 2 years ago #

    interesting approach, we'll think of adding some panel for that to the core. Thanks for sharing.

  3. Jigoshop Support - Michael
    Member
    Plugin Author

    Posted 1 year ago #

    Interesting

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Jigoshop
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags