John Snow

John Snow

Add new tab to WooCommerce product details page

We will show you how to add a new tab to product details page.
Here is the code –

Split cart items by shipping classes in WooCommerce

Assume you need to avail different shipping methods for different items in your store. But if both type items exists in your cart then how to do that ?

The first step you have to do is splitting the cart items into packages. Here in this code we will show how to do that —

Pre-populate Woocommerce checkout fields

Pre-populate Woocommerce checkout fields can be done with the following snippent –

Change flat rate shipping price

This article is about how we can change flat rate shipping charge. There are many scenarios like –
1. If a cart having few specified items from some category we need to change flat rate shipping.
2. For a particular area (country, state or zip) we need to change flat rate shipping.
And more on this not only flat rate shipping we many need to manipulate other shipping methods also.

So, if you know the shipping method id, it is easily achievable. Here I have showed how to modify flat rate shipping. But you can replace ‘flat_rate’ with your own method id.

You can put the line ‘$rates[$key]->cost = 25;’ under any condition. And remember you have a variable ‘$package’ which contains items of cart/package so you can loop through it and check for shipping classes or product category and apply logic according to it.

Show/Hide payment gateways according to shipping method

We often face this issue.¬† Sometimes we want to activate specific payment gateways¬† depending on selected shipping method. Here is the code —


Line 2 : We are getting the selected shipping method.
Line 4: We are checking whether it is local delivery or not (you can put your own shipping method or some other logic) .
Line 6: Now disabling payment gateways.
So in this way you can hide all the payment gateways which you don’t want to make available for the local delivery (or whatever).

Feel free to ask if you have any doubt.