cancel
Showing results for 
Search instead for 
Did you mean: 

Get the Tax Percentage from Order Details

Get the Tax Percentage from Order Details

I have tried the below line of code 

$_order->getTaxPercent();  to get the tax percentage from the order file.

But unable to get that.

I had get shipping details by using $_order->getShippingAddress();

Please suggest me to get the tax percentage

9 REPLIES 9

Re: Get the Tax Percentage from Order Details

Hello @anand_v,

 

 

You will get tax amount $_order->getTaxAmount() for render tax data on order object. 

Do you want tax percentage? So you have to calculate for it.

 

--
If my answer is useful, please Accept as Solution & give Kudos

 

Re: Get the Tax Percentage from Order Details

Hi @gelanivishal

 

In order details page, I have the tax percentage(VAT) for the products as 12%. 

I need to use the tax percentage for other purpose. 

How to get this by code?

Kindly suggest any solution for this.

Re: Get the Tax Percentage from Order Details

Hello @anand_v

 

Tax percentage save into item wise so you need to get all items and you need to do that.

 

Hope it will be answer of your question

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Get the Tax Percentage from Order Details

 Hello @anand_v

 

Now, I can get it

 

Tax rate is not based on order, but on order item, so you will need to check these: $orderItem->getTaxPercent() - For it you have to load orderitem object for it.

 

For invoice items you need to request the associated order item by calling $invoiceItem->getOrderItem()->getTaxPercent() - For it you have to load orderitem object for it..

 

To get the whole tax information of an order, you may use $order->getFullTaxInfo();, which returns the whole tax calculation result.

 

--
If my answer is useful, please Accept as Solution & give Kudos

 

Re: Get the Tax Percentage from Order Details

Hi @Sunil Patel.

 

I will understand your logic.But, please explain in code level to get that.

Re: Get the Tax Percentage from Order Details

Hi @gelanivishal

 

I have tried the 3 methods that you had said. But unable to get the percentage.

Re: Get the Tax Percentage from Order Details

Hello @anand_v,

 

Please check below code you will get full result for i

<?php
namespace Vendor\Module\Helper;

use \Magento\Framework\App\Helper\Context;
use \Magento\Sales\Api\Data\OrderInterface;
use \Magento\Sales\Model\ResourceModel\Order\Tax\Item;

class APIHelper extends \Magento\Framework\App\Helper\AbstractHelper
{
    /**
     * @var \Magento\Sales\Model\ResourceModel\Order\Tax\Item
     */
    protected $taxItem;

    public function __construct(
        Context $context,
        Item $taxItem
    ) {
        parent::__construct($context);
        $this->taxItem = $taxItem;
    }

    public function someMethod(OrderInterface $order)
    {
        $tax_items = $this->taxItem->getTaxItemsByOrderId($order->getId());
        var_dump($tax_items);
    }
}

--
If my answer is useful, please Accept as Solution & give Kudos

Re: Get the Tax Percentage from Order Details

Hi @gelanivishal

 

Sorry , I want to get this from e-mail template phtml file. 

Re: Get the Tax Percentage from Order Details

to get the tax percentage you have to first get the order items from order like :

$items = $order->getAllItems();
foreach($items as $item){
   $taxpercentage = $item->getTaxPercent();
}