• I tried to write such a short code of the author of the message.

    function  woocommerce_product_author_email2 () {
         the_author_email ();
    }
    add_shortcode('author_email', 'woocommerce_product_author_email2');

    I then made a code that sends a copy of the product message to the above short code.

    add_filter( 'woocommerce_email_headers', 'bbloomer_order_completed_email_add_cc_bcc', 9999, 3 );
     
    function bbloomer_order_completed_email_add_cc_bcc( $headers, $email_id, $order ) {
        if ( 'new_order' == $email_id ) {
            $headers .= "Cc: [author_email]" . "\r\n"; // del if not needed
        }
        return $headers;
    }
    

    It does not work as expected.
    What am I missing here?

    • This topic was modified 3 years, 9 months ago by moshe.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi there,

    You are missing a couple of things,

    1. shortcodes need to return value
    2. the_author_email displays a result – and is deprecated you shoul duse get_the_author_meta(‘usr_email’);

    function  woocommerce_product_author_email2 () {
         return get_the_author_meta('user_email');
    }
    add_shortcode('author_email', 'woocommerce_product_author_email2');
    

    and finally in your filter if you want to evaluate a shortcode you need
    do_shortcode('[author_email]');

    add_filter( 'woocommerce_email_headers', 'bbloomer_order_completed_email_add_cc_bcc', 9999, 3 );
     
    function bbloomer_order_completed_email_add_cc_bcc( $headers, $email_id, $order ) {
        if ( 'new_order' == $email_id ) {
            $headers .= "Cc: " . do_shortcode('[author_email]') . "\r\n"; // del if not needed
        }
        return $headers;
    }

    But I would ask, why do you need to define it as shortcode – just call get user meta directly

    add_filter( 'woocommerce_email_headers', 'bbloomer_order_completed_email_add_cc_bcc', 9999, 3 );
     
    function bbloomer_order_completed_email_add_cc_bcc( $headers, $email_id, $order ) {
        if ( 'new_order' == $email_id ) {
            $headers .= "Cc: " . get_the_author_meta('user_email') . "\r\n"; // del if not needed
        }
        return $headers;
    }
    Thread Starter moshe

    (@moshe1111)

    Hello
    Thank you for taking the time to fix my problem!
    It did become clear to me right now that that code was out of date, even though it was still active, and I replaced it with your code.
    I also made the repair you recommended me to make.
    But unfortunately, the two options you suggested, still do not work, apparently the author of the message in the order mail does not refer to the author of the product, so you need to understand why this is so, and what can be done to identify the product author’s email

    Hi,

    Sorry I’m only volunteering help so can’t write all your code for you, I’m sure thats not what you expect anyway.

    Essentially then you will need to
    1. look up the product and find its author id
    2. look up that id’s meta

    https://developer.www.ads-software.com/reference/classes/wp_query/
    https://developer.www.ads-software.com/reference/functions/get_the_author_meta/

    Thread Starter moshe

    (@moshe1111)

    It is designed to be a dynamic code
    And actually there’s something missing here,
    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Send an order message to the product author’ is closed to new replies.