I need to change the tax rate on quote items in a magento2 checkout process that is entirely done programmatically.

What I've found from various resources here on stackoverflow is that is possible to change the quote item's product tax rate


In my quote, however, I have many quote items, but they are the all the same catalog-product, only with differrent options aplied to them. Now, when I set the products tax rate like shown above, the last tax-class-id I set is used for ALL items in the quote.

I need a way to set the tax on the quote item directly. But


(e.g.) has no effect.

2 Answers 2


That's how you should do it:

Change the file app/code/Vendor/Package/etc/di.xml in your custom package by adding the line

<type name="Magento\Checkout\Model\Cart">
    <plugin name="interceptAddingProductToCart" type="Vendor\Package\Model\Checkout\Cart\Plugin" sortOrder="10" disabled="false"/>

Create the plugin


Now, add the content to the file above:


namespace Vendor\Package\Model\Checkout\Cart;

class Plugin
     * @var \Magento\Quote\Model\Quote
    protected $quote;

     * Plugin constructor.
     * @param \Magento\Checkout\Model\Session $checkoutSession
    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession
    ) {
        $this->quote = $checkoutSession->getQuote();

    public function beforeAddProduct($subject, $productInfo, $requestInfo = null)
        # Do something, here for instance, it remove TAX for giftvouchers
        if ($productInfo->getTypeId() == 'giftvoucher') {

        return [$productInfo, $requestInfo];
  • hi @medina, can we set fixed tax price for product when added to cart? May 14, 2019 at 11:35
  • I don't think this works, I've done this already but the cart still calculates the tax
    – Elland
    Jul 8, 2020 at 2:53

Yes, you can change.. You can try out below tricks:

  1. create custom tax rules and rates as per current quote address, this will apply tax rate to each product. Product rate you can calculate and save.

  2. use FPT , you can also customize it.. sales_quote_collect_totals_before use this event to change the fixed product tax value, this will add/change fixed amount to each product.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.