Public Ticket #3178570

billing and shipping countries do not match

Closed
Comments
2 Tickets 2
oroborosinstruments started the conversation 4 years ago on November 30, 2022 at 2:10pm

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,762
KingsPlugins replied 4 years ago on December 2, 2022 at 10:40pm

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://b2bkingplugin.com/docs/how-to-add-a-snippet-php-or-js/

Kind regards,

Stefan

Sign In