Perhaps one of the biggest headache for WooCommerce based eShop owner is that to determine the shipping cost settings on their site. Quite often they would be scratching their head around this issue. Now, luckily there are so many plugins out there that one should not take this issue too seriously.
Now, one easy solution could be charging the shipping cost based on the cart total or in other words total cost (excluding shipping, taxes etc.) of the items that the customer is ordering.
For the sake of explanation, lets think of about a hypothetical situation where you want to charge $10 shipping fee if the order total is $50 or less. If the order total is equal to $100 or less, you may want to charge $5 shipping. At the same time, if the order is more than $100, you may want to provide Free Shipping to your customer.
This is fairly a simple concept which may or may not fit your requirements but this is how you can do this without any plugin. This is how you can do it.
<?php
/**
* Charge Custom Shipping Fee
* Fee based on WC cart subtotal
*/
add_action('woocommerce_cart_calculate_fees','add_custom_shipping_fee');
function add_custom_shipping_fee() {
global $woocommerce;
// get cart subtotal
$st = WC()->cart->subtotal;
if ($st <= 50) {
$woocommerce->cart->add_fee(__('Shipping','woocommerce'), 10);
} else if ($st <= 100) {
$woocommerce->cart->add_fee(__('Shipping','woocommerce'), 5);
} else {
$woocommerce->cart->add_fee(__('Shipping','woocommerce'), 0);
}
}
?>
All you need to do is to simply copy and paste this snippet on your theme's functions.php page and update it. Rest should be done automatically when customer tries to check out.
What we are doing here is simply checking the cart total when customer tries to check out. If the subtotal (the price of the items only) is less than our desired sales amount(mentioned above), we are simply adding our custom shipping cost and only then calculating the grand total (including tax and stuff).
I hope you would find this snippet to be very useful. Let me know if you have any additional question or query on this regard. Thank you.
Comments