Add a custom text for a particular product on specific email notification in Woocommerce



PHP Snippet 1:

// Setting the email_is as a global variable
add_action('woocommerce_email_before_order_table', 'the_email_id_as_a_global', 1, 4);
function the_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email ){
    $GLOBALS['email_id_str'] = $email->id;
}

// Displaying product description in new email notifications
add_action( 'woocommerce_order_item_meta_end', 'product_description_in_new_email_notification', 10, 3 );
function product_description_in_new_email_notification( $item_id, $item, $order = null ){
    // HERE define your targetted product ID
    $targeted_id = 37;

    // HERE define the text information to be displayed for the targeted product id
    $text_information = __("There is an offer in this particular item", "woocommerce");

    // Getting the email ID global variable
    $refNameGlobalsVar = $GLOBALS;
    $email_id = $refNameGlobalsVar['email_id_str'];

    // If empty email ID we exit
    if(empty($email_id)) return;

    // Only for "New Order email notification" for your targeted product ID
    if ( 'customer_completed_order' == $email_id &&
        in_array( $targeted_id, array( $item->get_product_id(), $item->get_variation_id() ) ) ) {

        // Display the text
        echo '<div class="product-text" style="margin-top:10px"><p>' . $text_information . '</p></div>';
    }
}