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.
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.
Share Improve this question asked Jun 10, 2019 at 12:02 cag8fcag8f 1,9973 gold badges21 silver badges31 bronze badges1 Answer
Reset to default 1I 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