0

I am using Magento 2.3.5-p I have managed to hide price using CSS from the frontend, now I want to hide price and order total from transaction email like when a new order email is sent. How to do that, and which file I have to override in my child theme.

2
  • Hey, you can remove the whole blocks that tell the price, you can create a template in backoffice and apply that one. I you want to keep everything and just remove the price you can modify the block itself before it is sent to the email by using the email_order_set_template_vars_before observer I think, I did that with the payment_html block if you want an example how to use it
    – Rui Silva
    Jul 28 '20 at 10:13
  • can you elaborate more with example?
    – ishaq
    Jul 28 '20 at 17:04
0

I figured it out the template files used in emails are located at

/vendor/magento/module-sales/view/frontend/templates/email

Copied the email folder with all files inside my theme located at

/app/design/frontend/Vendor/Template_Name/Magento_Sales/templates/

and removed Price and Order Total from all .phtml files

Now email working perfectly without showing price.

0

Good you got a solution, I'll leave here an example of what I was saying for reference it might be helpful in the future. Basically what I did was using a module that is the same as adding a custom variable to email. In this example I edit the payment block in the new order email. It comes in a string so you can edit as a normal string. You can add a new variable if needed.

Something like this (I'll omit the usual registration.php etc etc)

event.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">    
            <event name="email_order_set_template_vars_before">
        <observer name="add_extra_data_to_transport" instance="Custom\PaymentBlockOverride\Observer\AddCustomVariable" />
    </event>
</config>

Observer/AddCustomVariable.p

<?php

namespace Custom\PaymentBlockOverride\Observer;

use Magento\Framework\Event\ObserverInterface;

class AddCustomVariable implements ObserverInterface
{  
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
       $transport = $observer->getEvent()->getTransport();
       $transport['payment_html'] /* The block I want to edit */
       /* Do something nice with it */

       $transport['new_variable'] = 'A cool new variable to use in your template'

    }
}

Use the new var in email as {{var new_variable}}.

Hope it might help someday :D

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.