Jump to content

IF statement if Product tax amount is equal to 0


Mian Waqas

Recommended Posts

Hello,

On product page if the TAX amount for a product is 0 , how i can write IF statement for it , so that if the tax amount is 0 the tax label shall be ABC, and if the tax amount is more then 0 then the label shall be XYZ.

i know the tax labeling configs etc on back office, but i am specifically asking about this how to get the tax amount value in IF/Else statment.

 

Thanks

Link to comment
Share on other sites

On 4/13/2023 at 5:10 AM, Mian Waqas said:

how to get the tax amount value

You can get it using $product.price*($product.tax_rate/100) from your product.tpl file

In your case, the code will be something like 

{if $product.tax_rate > 0}
	{assign var="tax_amount" value=$product.price*($product.tax_rate/100)}
	{assign var="tax_label" value="XYZ"}
{else}
	{assign var="tax_amount" value=0}
	{assign var="tax_label" value="ABC"}
{/if}

<p>{tax_label}</p>

 

Link to comment
Share on other sites

2 hours ago, AddWeb Solution said:

You can get it using $product.price*($product.tax_rate/100) from your product.tpl file

In your case, the code will be something like 

{if $product.tax_rate > 0}
	{assign var="tax_amount" value=$product.price*($product.tax_rate/100)}
	{assign var="tax_label" value="XYZ"}
{else}
	{assign var="tax_amount" value=0}
	{assign var="tax_label" value="ABC"}
{/if}

<p>{tax_label}</p>

Thank you for the reply, however i have tried to test these codes but not getting succeed. this i am doing on product-prices.tpl

Edited by Mian Waqas (see edit history)
Link to comment
Share on other sites

23 minutes ago, AddWeb Solution said:

Are you able to get $product.tax_rate and $product.price values in product-prices.tpl?

i can get $product.price but cannot get $product.tax_rate

i belive if somehow i can get the tax_rate  which will be 0 for some products there i can achieve my goal as follow.

{if $product.tax_rate eq "$ 0"}  

<span> abc </span>
     {else}
       <span> xyz</span>
    {/if}

Link to comment
Share on other sites

4 minutes ago, AddWeb Solution said:

May be try using the below snippet and let me know if it helps.

{assign var='tax_amount' value=$tax_calculator->getTaxAmount($product.price, $product.tax_rate)}
{if $tax_amount == 0}
	<span> {l s='ABC'} </span>
{else}
	<span> {l s='XYZ'} </span>
{/if}

 

Nop, i think this line, which is giving error {assign var='tax_amount' value=$tax_calculator->getTaxAmount($product.price, $product.tax_rate)} need correction

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...