1

For every product in WooCommerce I can add a purchase note (screenshot). This purchase note is displayed on all subsequent emails to the customer. Via custom PHP, how can I hide the purchase note on one specific email--the 'order completed' email in my case.

Is there a WooCommerce provided hook I can use? The main WooCommerce template governing this email is customer-completed-order.php. But that doesn't allow me to hide just the purchase note for a particular item--it allows me to hide all of the details for all items.

Alternatively, is there a way with PHP to check which particular email I am currently rendering, e.g.

if ($wc_email_template == "order_completed") {
// Execute this code.
}

If I can do that, then my issue would be resolved. The reason I say that is because there exists another WooCommerce email template, email-order-items.php. In it, I can indeed hide the purchase note. But this applies to all emails, which I don't want. So in this template, if I can insert a conditional to check if the email in-question is the 'order completed' email, it would resolve my issue.

Possible Solution?

From this previous post, maybe I can use the following to check if the email is the 'order completed' email.

$mailer = WC()->mailer();
$mails = $mailer->get_emails();
foreach ( $mails as $mail ) {
     if ( $mail->id == 'customer_completed_order' ) {
           // Execute my desired code here.
        }
     }
}

Not sure if that would that work though. This code snippet seems to check if the 'customer_completed_order' email exists. But in my case, I'm trying to insert that code into the PHP template that creates that very same email--so it sounds like the 'customer_completed_order' email will not exist yet, meaning this check will always fail.

Thanks.

1 Answer 1

1

I think you're correct about that code snippet only checking the for the availability of the email. But you can probably still make your alternative approach work: the WC_Email classes set $sending to true when they're in the process of sending. So you could check something like:

WC()->mailer()->emails["WC_Email_Customer_Completed_Order"]->sending
1
  • 1
    OK thanks for that. That check does indeed do what I need it to do. I'm going to move forward with that, and consider this the answer. Thanks!
    – cag8f
    Jun 11, 2019 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.