How to Create Flat Rate Shipping By Weight In WooCommerce

WooCommerce Flat Rate Shipping By WeightAre you looking for a way to introduce flat rate shipping by weight? You might have come across this functionality in many online stores. Customers are required to pay a shipping fee based on the weight of the products ordered.

WooCommerce allows you to add flat rate shipping to a shipping zone, but it does not support weight based shipping.

There are many plugins, which can help you to achieve this. But it is important to note that having many plugins on your site will slow it down. We recommend using custom PHP scripts as this is the safest way to make changes to your site.

WooCommerce Flat Rate Shipping By Weight

In this post, we’ll share how you can provide free shipping by weight. This will help you entice customers to your store.

However, it is important to note that for you to enable weight based shipping, you need to make sure your products have weight.

This is the most common mistake most people make. You should also make sure that you have entered the correct weight.

You should also note which shipping zone is applied when calculating the shipping fee.

Let’s look at how you can effectively charge shipping based on weight.

How to Charge Flat Rate Shipping By Weight in WooCommerce

For illustration purposes, we will have a three weight based shipping tier:

  • For packages under 10kg, we charge $10
  • We will charge $20 for packages under 20kg (but more than 10kg)
  • And finally, for packages over 20kg, we charge $50

There are no restrictions to the number of tiers you can set. You can be creative and create a very complex tiers hierarchy.

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. Create a new shipping zone by going to WooCommerce > Settings > Shipping. Select or create a shipping zone
  3. Create three flat rate shipping tiers by click on Add shipping method and select the flat rate.
  4. Click on the Add shipping method button. You will see there is an option like this that appears. Click on Edit.
  5. Enter the details for the tier. Repeat the same procedure for the other tiers. For example, in the screenshot below, the shipping fee is $10 for a package less than 10kgflat rate
  6. After repeating for the other 2 tiers, you should have something like this:tiers
  7. For the shipping rates to work, you need to enter the following code snippet in the functions.php file:
[php] add_filter( ‘woocommerce_package_rates’, ‘njengah_weight_based_shipping_tiers’, 10, 2 );

   function njengah_weight_based_shipping_tiers( $rates, $package ) {

         if ( WC()->cart->cart_contents_weight >= 10 ) {

          foreach($rates as $key => $value)

    {

      if ($value->cost != 10)

        unset($rates[$key]);

           }

          } elseif ( WC()->cart->cart_contents_weight >= 20 ) {

          foreach($rates as $key => $value)

    {

      if ($value->cost != 20)

        unset($rates[$key]);

          }

          } else {

               foreach($rates as $key => $value)

    {

      if ($value->cost != 50)

        unset($rates[$key]);

            }

           }

     return $rates;

   }
[/php]

  1. This is the outcome:flat rate shipping based on weight

Conclusion

From this tutorial, you have seen how it is very easy to offer flat rate shipping based on weight. This strategy is used by many stores to entice customers who like shopping in small quantities. This means that customers with heavier products will have to pay more. There is no need to increase the price to cover the shipping costs.

If you need further customization, please contact a qualified WordPress developer

Similar Articles