cancel
Showing results for 
Search instead for 
Did you mean: 

Not working if condition for order total is greater than 200 in email template

SOLVED

Not working if condition for order total is greater than 200 in email template

Hello
I have added below code to check the order total is greater than 200 ,  but it is not working.
 {{var order.getGrandTotal() |format=number}}
value is coming in above line.

{{if order.getGrandTotal() >= 200}}
Greater than or equal 200............
{{/if}}
{{if order.getGrandTotal() < 200}}
Less than 200............
{{/if}}

Can anyone give me solution .
Thank you in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Not working if condition for order total is greater than 200 in email template

Hello @varshanema519b ,

 

If condition doesn't work that way in email template, you can add a custom block in email template like below :

{{block class='Magento\\Framework\\View\\Element\\Template' area='frontend' order=$order template='Vendor_Module::email/custom.phtml'}}

Now, create a file app/code/Vendor/Module/view/frontend/email/custom.phtml

and add below code :

<?php
    $order = $block->getOrder();
    if($order->getGrandTotal() >= 200){
         echo "Greater than or equal 200....";
    }else{
        echo "Less than 200....";
    }
?>
Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

View solution in original post

1 REPLY 1

Re: Not working if condition for order total is greater than 200 in email template

Hello @varshanema519b ,

 

If condition doesn't work that way in email template, you can add a custom block in email template like below :

{{block class='Magento\\Framework\\View\\Element\\Template' area='frontend' order=$order template='Vendor_Module::email/custom.phtml'}}

Now, create a file app/code/Vendor/Module/view/frontend/email/custom.phtml

and add below code :

<?php
    $order = $block->getOrder();
    if($order->getGrandTotal() >= 200){
         echo "Greater than or equal 200....";
    }else{
        echo "Less than 200....";
    }
?>
Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy