How to Set Up WooCommerce Per Product Shipping

WooCommerce Per Product ShippingAre you looking for a way to charge customers per the quantity of products in your cart? It is not a complicated process to introduce WooCommerce per product shipping in your WooCommerce store. This is better than a flat rate fee and each product is accounted for. This means that you will not incur the shipping cost.

This is definitely doable and you do not have to be a professional to achieve this. Also, WooCommerce has a built-in solution to offer quantity-based shipping.

You do not even have to use a plugin or code snippets.

WooCommerce Per Product Shipping

In this post, we will share how you can use the built-in option to configure shipping rates based on the quantity of products in the cart.

If you are a developer and you like using code snippets to make changes in your store, read along as we will share a custom snippet that we created.

Let’s look at how you can achieve this.

Steps to Charge WooCommerce Shipping Per Quantity

Most WooCommerce shop owners use built-in shipping zones and rates to create their shipping fee structures. You can find the settings under WooCommerce > Settings > Shipping.SHipping zones

You will notice that most of the shipping methods are flat rate methods. We have also included free shipping and shipping by weight.

It is worth mentioning that you can do more with flat rates than simple costs.

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the dashboard menu, go to WooCommerce > Settings > Shipping.
  3. Create or select a shipping zone, and add a flat rate as the shipping method.
  4. When you configure the settings, remember to read the tooltips in WooCommerce core more frequently. They can help you understand more about the built-in features.tooltips
  5. From the screenshot above, you can see that it is possible to add advanced costs such as quantity-based costs or additional fees, to your flat rate shipping. However, you have to include the item quantity in your shipping cost formula with the [qty] shortcode.
  6. Instead of charging $5 per order, we can charge $5 per item in the cart. This is the outcome:shipping per quantity

Creating More WooCommerce Shipping Tiers

Alternatively, you can use more complex shipping schemes or tiered pricing using the woocommerce_shipping_rate_cost filter.

You can use it to adjust the cost of any shipping method programmatically. You should only use this method if you are comfortable with PHP code and WordPress hooks.

Steps to Creating More WooCommerce Shipping Tiers

Here are the steps you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the dashboard menu, go to WooCommerce > Settings > Shipping.
  3. Select your shipping zone and add a flat rate shipping method.
  4. When configuring the settings, add the flat rate shipping cost as shown below:flat rate
  5. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will filter the method cost, multiplying this base cost by our box count. We will get the box count by rounding the cart item quantity divided by 2. You can also use the modulus operator here to check for instances.
  6. Add the following code to the functions.php file:
[php] /**

 * Filters the shipping method cost to account for tiered quantity pricing.

  */

function njengah_wc_shipping_cost_tiers( $cost, $method ) {

            // TODO: change the numbers in this array with your desired instance IDs

            // see if this shipping instance is one we want to modify cost for

            if ( in_array( $method->get_instance_id(), array( 22, 23 ) ) && WC()->cart ) {

                        $cart_item_count = WC()->cart->get_cart_contents_count();

                        // if we have items that need shipping, round the quantity / 2 to the nearest whole number

                        // this produces tiered cost increases for every 2 items

                        if ( $cart_item_count > 1 ) {

                                    $cost = round( $cart_item_count / 2 ) * $cost;

                        }

            }

            return $cost;

}

add_filter( ‘woocommerce_shipping_rate_cost’, ‘njengah_wc_shipping_cost_tiers’, 10, 2 );[/php]

  1. Remember to add the correct shipping ID. You can get this by hovering over the link to each shipping rate and you’ll see &instance_id=number in the URL
  2. This is the outcome:shipping

Conclusion

In this post, you have learned how to charge shipping per product. We have also shared how you can create tiers using PHP code If you have any problems, please consider contacting a qualified WordPress developer.

Similar Articles

  1. How to Add WooCommerce Custom Checkout Message