Add an additional cost to shipping service based on Shipping Class
The code snippet facilitates you to add an additional shipping cost to the required service(s) for products which belong to the specific class(es).
Add the following code to your functions.php or anywhere relevant.
In the above code:
– $shipping_class_ids contains the IDs of shipping class(es) for which you want to add an additional cost for shipping.
– $extra_cost contains an additional cost which is to be added to shipping.
– $shipping_services contains IDs of services for which you want to add an additional cost for shipping.
If $shipping_class_ids matches with the shipping class ID of the cart product, then $shipping_class_exists becomes true. If $shipping_class_exists exists, then the cost of all the listed services is added with $extra_cost and saved in $available_shipping_methods. The Function returns $available_shipping_methods which contains an additional cost of shipping.