0

I'm using this to modify the email that is sent to our client for their records, but I don't want the same info displayed to their customer invoice.

add_action( "woocommerce_email_order_details", "wc_get_transaction");

function wc_get_transaction( $order ) {
    echo '<span style="color:#555;font-size:1.5em;">Transaction ID: '.get_post_meta( $order->id, "_transaction_id", true ).'</span>';

}

I tried this:

if ( ! $sent_to_admin ) {
    add_action( "woocommerce_email_order_details", "wc_get_transaction");

    function wc_get_transaction( $order ) {
        echo '<span style="color:#555;font-size:1.5em;">Transaction ID: '.get_post_meta( $order->id, "_transaction_id", true ).'</span>';

    }
}

Doesn't work though. I'm using this in my functions.php

How can I get this so it only sends to the admin?

1 Answer 1

0

The hook woocommerce_email_order_details has 4 parameters which can help you to identify the correct message.

add_action( 'woocommerce_email_order_details', 'so274215_add_transaction_id', 10, 4);

function so274215_add_transaction_id( $order, $sent_to_admin, $plain_text, $email ){
    // decide here wether to show your transaction id
    if ( ! $sent_to_admin ) 
        echo '<span style="color:#555;font-size:1.5em;">Transaction ID: '.get_post_meta( $order->id, "_transaction_id", true ).'</span>';
}

As far as I remember the last parameter $email contains the name of the current message, just in case you want to go more into detail.

if( 'WC_Email_Customer_On_Hold_Order' == $email ) ...

Your Answer

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

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