Quick Tutorial: How To Get Product Price Including Tax In Magento 2

by admin

By default, Magento 2 displays product price that does not include the tax.

It might annoy your customers when they only find out the tax amount after going through the long process of selecting and then adding the product to the cart.

So in this article, we will show you the solution to get product price including tax in Magento 2.

Let’s go!

Why Should You Display Price With Taxes?

Depending on the country your store is selling, you should/must include the tax in your product price.

For example, in Canada and the US, customers are used to seeing the products without taxes. However, in Europe, customers would expect to see taxes on the products’ prices.

So if it’s a mandate by the country’s law, you should display the price with taxes and show a note that says ‘inclusive of all taxes.’

How To Get Product Price Including Tax In Magento 2?

To get product price including tax in Magento 2, you just need to add the following code: 

<?php

namespace Meetanshi\Module\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Helper\Data as TaxHelper;

class Data extends AbstractHelper
{
    protected $productModel;
    protected $taxHelper;

    public function __construct(
        Context $context,
        Product $productModel,
        TaxHelper $taxHelper
    )
    {
        $this->productModel = $productModel;
        $this->taxHelper = $taxHelper;
        parent::__construct($context);
    }

    public function getProductPrice($productId)
    {
        $product = $this->productModel->load($productId);
        $price = $this->taxHelper->getTaxPrice($product, $product->getFinalPrice(), true);
        return $price;
    }
}

Can You Set Up a Different Product Tax Per Store View?

As you know, different countries or states have different tax policies. However, the default Magento 2 only supports adding the same tax rate to products on your entire website. 

Thus, if your website is selling globally, it’s necessary to set a different tax for each store view.

So can you set up a different product tax per store view in your Magento store?

The answer is yes!

Here to introduce you to the best tool to configure tax per store view:

magento-2-tax-per-store-view

Magento 2 Tax per Store View by BSS

This module enables you to select Store View as the scope of tax class attributes. Using this extension, you can easily charge different taxes in different stores or store views.

It also allows assigning various tax classes for tax rules and various rates of tax per store view.

Conclusion

In this article, we have shown you how to get product price including tax in your Magento 2 store.

We hope this blog is helpful and good luck to you!

BSS Commerce is one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bringing high-quality products and services to optimize your business effectively. Furthermore, we offer FREE Installation – FREE 1-year Support and FREE Lifetime Update for every Magento extension.

CONTACT NOW to let us know your problems. We are willing to support you every time.

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.