Okay
  Public Ticket #3178570
billing and shipping countries do not match
Closed

Comments

  •  2
    oroborosinstruments started the conversation

    Hi there, 

    we need again your help:
    Prior to purchase, your team said they could send a code snippet that blocks checkout if the billing and shipping countries do not match and instructs users to contact us.
    Can you help us with that?

    Many thanks,

    Paolo

  •  2,218
    WebWizards replied

    Hi Paolo,

    You can add the following PHP code snippet to the site:

    add_action('woocommerce_after_checkout_validation', function($fields, $errors) {
        $b_country = WC()->customer->get_shipping_country();
        $s_country = WC()->customer->get_billing_country();
        if ($b_country !== $s_country){
            $errors->add( 'validation', 'The billing and shipping country must be the same. Please contact us if they are different.');
        }
    }, 10, 2);
    

    The way this works is that if the user clicks on 'place order' at the end of the checkout, if the countries are different, the user will see the following error:

    7510126804.png


    Of course, you can modify the above text per your needs.


    The PHP snippet can be added to functions.php, or by following our guide here: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/


    Kind regards,

    Stefan

  •  2
    oroborosinstruments replied

    Hi Stefan,

    it works perfectly! thank you so much!


    All the best,

    Paolo