• Resolved macman43

    (@macman43)


    Free shipping was set up for all products being shipped to all US States except AK and HI. It came to our attention recently that an order placed back in February 2024 being shipped to Hawaii was given free shipping. Because of what was being shipped, the shipping cost for us was extremely high and as a result there was a substantial loss on the sale. Not sure what version of Woocommerce was used at the time, if there was a glitch in the shipping section of the plugin or what, but this cannot happen again. Please advise.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Stef

    (@serafinnyc)

    Hello @macman43 you’d need to provide us with screenshots of all your settings for shipping in order to get a better understanding. Make sure to cover the zones, inside the zones and anything else pertinent. Thanks

    Thread Starter macman43

    (@macman43)

    Attached are the shipping screenshots requested.

    Stef

    (@serafinnyc)

    Thanks for this @macman43 I don’t understand how you were able to add states in the zip code field. Are you using a 3rd party app for that? that’s not native to WooCommerce core.

    I believe you cut off the List Per Postcode. Normally, we do the entire US and then write a hook or use a 3rd party app to block those two states. I’m not aware of any app, I’m a developer, so I can only offer a hook.

    What I would do if you want is change the Zone Region be “United States” then add this snippet to your functions.php file near the bottom. This will block those two states. Then put a notice on the checkout page and shipping policy page that denotes AK and HI are not eligible for Free Shipping.

    function custom_disable_free_shipping_for_specific_states($rates, $package) {
        $restricted_states = array('AK', 'HI'); // Alaska and Hawaii
    
        // Check the destination state of the package
        if (isset($package['destination']['state']) && in_array($package['destination']['state'], $restricted_states)) {
            // Loop through the available shipping rates
            foreach ($rates as $rate_id => $rate) {
                // If a free shipping method is found, remove it
                if ('free_shipping' === $rate->method_id) {
                    unset($rates[$rate_id]);
                }
            }
        }
    
        return $rates;
    }
    add_filter('woocommerce_package_rates', 'custom_disable_free_shipping_for_specific_states', 10, 2);
    

    How to Add the Code:
    1.) Go to your WordPress dashboard.
    2.) Navigate to Appearance > Theme Editor or use a code editor if you have access to the server files.
    3.) Open the functions.php file of your active theme.
    4.) Copy and paste the provided code into the functions.php file.
    5.) Save the changes.

    Or use FTP (safest method)

    This code will ensure that free shipping is not available for orders shipping to Alaska or Hawaii. Let me know if you need any more help with this!

    • This reply was modified 10 months ago by Stef.
    Stef

    (@serafinnyc)

    Sorry, forgot to list the official documentation on setting up zones

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @macman43

    It seems like there might have been a configuration issue in the Shipping Zone settings back then. Make sure you have excluded Hawaii and Alaska from zone regions.

    If the settings are correct and the issue persists, it might be due to a plugin conflict or a glitch in the version of WooCommerce you are using. We recommend updating to the latest version and checking if the issue remains.

    However, @serafinnyc shared an excellent solution to prevent this issue from occurring in the future. This code will effectively block free shipping to Alaska and Hawaii.

    I hope this helps! If you have any other questions, feel free to ask.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @macman43

    I’m marking this topic as “resolved” due to recent inactivity. If more assistance is needed, feel free to post back here or open a new topic.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Free shipping doesn’t always work’ is closed to new replies.