Free Shipping – Limit by country

If you want to limit free shipping to specific countries only, you can use the pwbf_free_shipping_is_available hook.

For example, to limit free shipping for only US addresses, follow these steps:

Note: if you prefer to add the code to your functions.php you can do that instead of using Code Snippets.

1. Download the free Code Snippets plugin: https://wordpress.org/plugins/code-snippets/
2. Create a Snippet with the following code (Note: If you are more comfortable with editing your functions.php you can do that instead of Code Snippets.):

function custom_pwbf_free_shipping_is_available( $is_available, $black_friday ) {
    if ( $is_available) {
        $shipping_country = WC()->customer->get_shipping_country();

        // Perform your country verification here.
        if ( $shipping_country != 'US' ) {
            $is_available = false;
        }
    }

    return $is_available;
}
add_filter( 'pwbf_free_shipping_is_available', 'custom_pwbf_free_shipping_is_available', 10, 2 );
Skip to content