How to Remove Header Image from New Order Template in Wordpress Woocommerce

I've set a header image for my woocommerce email settings, but I only want it to display in some emails and not others. Does anyone know how I can achieve this, specifically for the 'new order' notification?

Answer №1

To customize the email templates in Woocommerce, follow these steps:

  • Go to the email tab under settings in Woocommerce
  • Locate and click on "Processing order"
  • Scroll down to find the "HTML template" section
  • Click on the "Copy file to theme" button
  • After copying, select the "View Template" button to edit the file
  • In the editor, search for
    ?> <?php do_action('woocommerce_email_header', $email_heading); ?>
  • Open the email-header.php file and copy its content from
    $bg       = get_option( 'woocommerce_email_background_color' );
    until the end
  • Replace
    ?> <?php do_action('woocommerce_email_header', $email_heading); ?>
    with the content from email-header.php
  • Delete the code block:
    <?php if ( $img = get_option( 'woocommerce_email_header_image' ) ) {
    echo '<p style="margin-top:0;"><img src="' . esc_url( $img ) . '"
    alt="' . get_bloginfo( 'name' ) . '" /></p>'; } ?>

The order receipt emails will now exclude the header image. You can apply similar changes to other email templates as needed.

Answer №2

The above method works perfectly fine. Alternatively, we can achieve the same result through a simple step.

To begin, open the email-header.php file located at /wp-content/plugins/woocommerce/templates/emails

Navigate to WooCommerce => Settings => Emails => New Order in the Admin Panel Copy the text from the Email-Heading textbox. In my case, it reads as “New customer order”.

In the "email-header.php" file, locate the code below under the “template_header_image” section

<?php
      if ( $img = get_option( 'woocommerce_email_header_image' ) ) {
        echo '<p style="margin-top:0;"><img src="' . esc_url( $img ) . '" alt="' . get_bloginfo( 'name' ) . '" /></p>';
        }
?> 

Important Tip: Ensure that in the code snippet below, the comparison text within the “if condition - if( $email_heading != "New customer order")” is copied directly from the Email-Heading textbox in the WooCommerce admin panel.

Replace the code above in "email-header.php" with the following code

<?php
     if( $email_heading != "New customer order"){
        if ( $img = get_option( 'woocommerce_email_header_image' ) ) {
            echo '<p style="margin-top:0;"><img src="' . esc_url( $img ) . '" alt="' . get_bloginfo( 'name' ) . '" /></p>';
        }
     }

?>

If you wish to implement this for other emails, ensure each distinct Email-Heading corresponds to its respective category.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking to use AJAX to seamlessly upload images along with data to a database?

Is it possible to upload an image and data to a database without refreshing the page? I have a form that includes input fields for collecting data, a browse button for selecting an image (using input type="file"), and a submit button. When the user click ...

PHP Commenting System with Hierarchical Structure

I am looking to create a commenting system similar to Discus or Reddit. In my comment database, I have a field called "id_answer" which is set to 0 by default. When a user replies to another comment, this field will be populated with the "id" of the parent ...

PHP: Inquiry about the IF statement

I have a simple login form and I want to include some validations. Here is what I have come up with: $errors = array(); if($_SERVER['REQUEST_METHOD'] == 'POST'){ if(0 === preg_match("/.+@.+\..+/", $_POST['email'])) ...

Creating modular MVC components in Zend Framework is a key skill that developers need to master

I've been facing challenges in creating modular reusable components within my Zend Framework application. I'm not talking about Zend Framework modules, but rather the ability to have a reusable MVC widget. The issues I'm encountering may be ...

Convert JSON data without backslashes using json_encode

I am having an issue where I retrieve a JSON encoded array from the database, modify one field, and then save it again. However, when I use json_encode, it removes the backslashes and as a result, the text is not displayed correctly on my site. $data_de=j ...

Converting the creation time from JSON format and replacing any special characters in the input

I'm facing a challenge in describing this. I am using the Facebook graph to showcase my pages' activity on Facebook/Twitter (via Facebook) on a website. Everything is going smoothly, except for formatting the created_time data properly. I have ve ...

Notification not appearing in PHP

When working with a specific php file, I am encountering an issue where the alert box I have placed before the header is being ignored and the header is executed directly. Can anyone assist me in resolving this issue? Any help would be greatly appreciate ...

Tips for incorporating custom blocks into page content while utilizing get_the_content() method

Our Wordpress theme has a custom page template that displays the content from 3 different pages in a tabbed layout. One of these tabs includes a glossary section, which looks like: <div class="glossary-content content e8-tab-panel" data-tab=&q ...

Experiencing connectivity issues with Apache Server on XAMPP

Just recently, I decided to set up the XAMPP Control Panel for my PHP project. However, I encountered an issue where it is not allowing me to connect to the Apache server. The XAMPP Control Panel keeps displaying an error message whenever I try to establis ...

The Mysql query is only retrieving the initial character from the strings

Could someone please help me figure out what I'm missing? The SQL query below is only returning the first letter of each string from my database: $result = mysql_query("SELECT * FROM users) or die("error in the query"); Thank you. Update $resul ...

JavaScript and Ajax are functioning properly in Mozilla Firefox, however there seem to be some compatibility issues with Google Chrome

I have a form that serves the dual purpose of registration and login, and I am using JavaScript Ajax to submit it. While it works smoothly in Mozilla Firefox, it fails in Chrome and IE. The goal is to execute an AJAX and PHP script that checks the databa ...

In every error occurrence, Laravel 6 consistently displays an undefined index: model message

Recently, I made the transition to Laravel 6 and successfully set up my development environment using PHP 7.4, mysql 8, and nginx on Docker. While working on migrating a website to Laravel 6 and familiarizing myself with the framework, I encountered an iss ...

How can one display blog data (stored as a PDF) from a database alongside other different results (stored as

I have successfully displayed a PDF file from my database as a blob using the header("Content-type:application/pdf") method. Now, I am looking to also display some additional string results along with this PDF file. Is it feasible to achieve this while d ...

What could be the reason my foreach loop is not being run?

After creating a login form that successfully grants access upon entering the correct email and password, there seems to be an issue. A foreach loop is implemented to test all results, with the assumption of only one account existing. foreach ($result as ...

Utilize PHP for loop to output form values into XML format

Hey there, I'm currently facing an issue with setting up a for loop in PHP to transfer the content of an HTML form into an XML file. It works perfectly fine without the for loop, but throws errors when included. Can anyone provide some insights? It&ap ...

Is there a method to access a website, trigger JavaScript functions, and subsequently retrieve the HTML content using PHP?

I am currently exploring options to access a webpage, execute JavaScript functions on it (thus altering the HTML content), and eventually save the modified version of the page. I'm uncertain if this approach is feasible, and if not, are there alternat ...

Decode JSON with an integer as the key

Alright, so here's the situation. I've got this massive JSON feed and everything is running smoothly. However, there's just one small hiccup Currently, my approach involves: $json=file_get_contents($source); $data = json_decode($json,true) ...

Avoid Refreshing Form in Codeigniter

In order to avoid receiving the 'confirm form resubmission' warning, it is commonly advised to use GET method. However, in Codeigniter, the preferred method is often POST due to compatibility issues with form helper functions and other features. ...

Secret method to effortlessly load a php file using jQuery without revealing your technology stack

In the current landscape, Developers and Professionals are increasingly opting for PHP templates for their projects. This choice is driven by two main factors - their ease of management and the convenience of not needing to overtly showcase the technology ...

How to loop through a JSON array in PHP and retrieve only the final

Hello, I am encountering an issue with my JSON data. I have nested foreach loops within a for loop... don't ask why. The problem is that the inner foreach loop foreach( $result2 as $rowx ) only outputs the last record. The database query is functioni ...