I want to count shipping cost based on number of products add on cart like,
If I purchase one mobile then it will count shipping cost as 2.5 and after more than two or two mobile I purchased then shipping cost will be 5.0
<?php
$qty(1) * 2.5 = 2.5
$qty(2) * 2.5 = 5.0
$qty(3) * 2.5 = 5.0
?>
So is there any idea or suggestion how to count the shipping cost based on number of products ?
You can add a custom fee: Add to theme functions.php or use a plugin
Go ahead with Woocommerce filter
woocommerce_package_rates
. Where you can customize all the shipping rates available in cart page.Here is the code for adding extra cost to all items for both domestic and international shipement
So this answer will do it in all cases:
1) First you will need to set a "Flat rate" shipping method for each Shipping Zones which cost will be set to
2.5
(in your WooCommerce shipping settings).2) Adding this code that will calculate for each cart items (based on the total quantity of items) the new updated shipping cost:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested on WooCommerce 3+ and works