I'm trying to add a specific function to my customer-completed-order template file in WooCommerce.
I want that function to check if an order note is containing specific word "Loren ipsum" and if yes, show a my selected message.
This is how my customer-completed-order.php email template file looks like:
<?php
/**
* Customer completed order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-completed-order.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates\Emails
* @version 3.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php /* translators: %s: Customer first name */ ?>
<p>
<?php
$comment_obj = get_comment( $comment_id );
$customer_note = $comment_obj->comment_content;
$word = "Loren ipsum";
$mystring = $customer_note;
$order_id = $order->get_id();
// ACF field, will give an error if you don't use this specific plugin
//$pristatysimePatys = get_field('pristatysime_patys', $order_id);
if (strpos($mystring, $word) !== false) {
$message = "Your order number " . $order_id . " is sended. " . $customer_note ." .";
} elseif ($pristatysimePatys) {
$message = "Your order number " . $order_id . " is sended. The custom field checkbox in order are selected.";
} else {
$message = "There are no Loren Ipsum in order notes and custom field with checkbox is not selected.";
}
printf($message);
?>
</p>
<?php
/*
* @hooked WC_Emails::order_details() Shows the order details table.
* @hooked WC_Structured_Data::generate_order_data() Generates structured data.
* @hooked WC_Structured_Data::output_structured_data() Outputs structured data.
* @since 2.5.0
*/
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
But I do a mistake somewhere, because even if the words "Loren ipsum" is in order note, it will show my else result in the email. Any advice?