Skip to content
Advertisement

How to make a custom cart fee to be taxable in WooCommerce

Found exactly the snippet I was looking for to add a fixed fee amount to each individual cart item regardless of price. This site sells tires. So each tire will be charged 3$.

Here is the code I’m using and works:

JavaScript

I’m not very good with PHP and I’m learning as I go. I did spend 3 hours trying to modify this code so that the $3 fee would be TAXED as well. But I couldn’t figure it out.

Below is what I tried as one of the attempts to have the fee taxed as well but it doesn’t work:

JavaScript

What I am doing wrong? Any help please.

Advertisement

Answer

To make it work, replace in your code the line:

JavaScript

with the following code line (see WC_Cart add_fee() method):

JavaScript

So your correct hooked function code will be:

JavaScript

Code goes in functions.php file of the active child theme (or active theme). It should works.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement