I want to get tax rate (percentage) on product-view page. Following code only shows text of tax:


Thanks for help! martn

3 Answers 3


I achieved getting tax rates by using \Magento\Tax\Api\TaxCalculationInterface:

$rate = $this->taxCalculation
              ->getCalculatedRate($productTaxClassId, $customerId, $storeId);
  • hi @Lukas,can we get the tax amout from product id in magento2? May 14, 2019 at 9:37
  • 1
    where need to keep this piece of code can you please give complete instruction.
    – irshad
    Jan 31, 2020 at 10:45
  • @jafarpinjar Tax Amount depends on given Tax Rules. Tax rules depends on products tax class, country, customer group and so on. So if you have a product id try to find the products tax class id and use my code to get the customers tax amount. Jan 31, 2020 at 11:21
  • @irshad use dependency injection (DI) to inject \Magento\Tax\Api\TaxCalculationInterface $taxCalculation Jan 31, 2020 at 11:22
  • @Lukas: How can we display separate tax on selecting particular stores from the dropdown? magento.stackexchange.com/questions/304011/…
    – irshad
    Feb 13, 2020 at 8:51

You can get tax rate by:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$taxCalculation = $objectManager->create( 'Magento\Tax\Model\Calculation\Rate' )->load( <tax_rate_id> , 'tax_calculation_rate_id' );

$rate = $taxCalculation->getRate();

where <tax_rate_id> get from Tax Zones and Rates admin screen /tax/rate/ , or you can get it programmatically with TaxRuleModel

  • Load is deprecated, is there another way to do this?
    – PathToLife
    Jan 11, 2019 at 21:20

We can get rate object by instantiating 'Magento\Tax\Model\Calculation\Rate' class and calling loadByCode() method on the instance. The tax_code needs to be passed as a parameter of the method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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