Categories

Thursday, May 2, 2024
#919814419350 therichposts@gmail.com
WoocommerceWoocommerce HooksWordpress

Exclude a specific shipping class from qualifying for free shipping in WooCommerce

EXCLUDE A SPECIFIC SHIPPING CLASS FROM QUALIFYING FOR FREE SHIPPING IN WOOCOMMERCE

woocommerce free shipping exclude for some classes, Hide other shipping methods when “Free Shipping” is available, Hide free shipping for specific shipping classes exclusively in Woocommerce.


To exclude a specific shipping class, such as one for bulky items, from qualifying for free shipping in WooCommerce, you can modify the settings for the free shipping method. Here’s how to adjust your WooCommerce settings to ensure that orders containing bulky items do not qualify for free shipping:

  1. Log in to your WordPress dashboard. Navigate to your website’s admin area.
  2. Go to WooCommerce settings. On the left sidebar, hover over “WooCommerce” and click on “Settings.”
  3. Access the Shipping tab. This is where you manage all your shipping settings.
  4. Select the appropriate shipping zone. Click on the shipping zone where you’ve set up free shipping.
  5. Edit the free shipping method. Click on the “Free Shipping” method you previously created to edit its settings.
  6. Adjust the free shipping requirements. In the settings for free shipping:
  • In the “Free Shipping Requires…” dropdown, choose “A valid free shipping coupon / A minimum order amount / A minimum order amount OR a coupon.”
  • Ensure you have set the minimum order amount as needed (e.g., £30).
  1. Use shipping classes to exclude bulky items:
  • First, ensure you have a shipping class created for bulky items. Go to WooCommerce > Settings > Shipping > Shipping classes and make sure there’s a class labeled appropriately (e.g., “Bulky”).
  • Then, go back to the shipping zone settings and click on “Edit” under the Free Shipping method.
  • Look for an option to exclude shipping classes from free shipping. WooCommerce by default does not offer an explicit option to exclude classes directly from the free shipping method settings. If such an option is not visible, you will need to add custom code to your site.
  1. Add custom code to function.php: If WooCommerce’s default options don’t support excluding shipping classes directly, you can add the following custom code to your theme’s functions.php file:
function disable_free_shipping_for_bulky($is_available, $package) {
    // Define the shipping class you want to exclude
    $excluded_class = 'bulky'; // Use the slug of your bulky shipping class

    // Check each item in the cart
    foreach ($package['contents'] as $item) {
        if ($item['data']->get_shipping_class() == $excluded_class) {
            return false; // Free shipping is not available
        }
    }

    return $is_available;
}
add_filter('woocommerce_shipping_free_shipping_is_available', 'disable_free_shipping_for_bulky', 10, 2);

Replace 'bulky' with the actual slug of the shipping class for bulky items in your WooCommerce setup.

  1. Save changes and test. After adding the custom code, make sure to test the checkout process to ensure that the free shipping option does not appear when a cart contains items from the bulky shipping class.

By using these steps, you can effectively exclude orders containing bulky items from qualifying for free shipping in your WooCommerce store.

Thanks

Jassa

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.