• Resolved avinashdigitl

    (@avinashdigitl)


    => Hello, i have created 2 fields (Gift, Gift Email), if user purchase product and enter Gift email, then i want to send order email to “Gift Email” field value.

    => Is it possible with this plugin?

    => if not, then can you please just share where are this value stored in order, and how can we retrieve this value in “woocommerce_email_recipient_new_order” hook?

    1.Gift:
    =>2023081777653874_gift [https://prnt.sc/peVssaJ4EoKL]

    2. Gift Email:
    => 2023081777653874_gift_email [https://prnt.sc/j_2tp1oEOH49]

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter avinashdigitl

    (@avinashdigitl)

    Hi, is there any feedback on this point?

    Plugin Support rzepsen

    (@rzepsen)

    Hi avinashdigitl

    Thank you for your patience.

    add_filter( 'woocommerce_email_recipient_new_order', function( $recipient, $order, $email_class ) { $items = $order->get_items(); foreach ( $items as $item ) { $meta_data = $item->get_all_formatted_meta_data(); foreach ( $meta_data as $meta ) { if ($meta->key == 'field label') { // yes field label with spaces - not field name return $meta->value; } } } return $recipient; }, 10, 3 );

    This is an example implementation that you can adapt for yourself. E.g. perhaps you want a field to be additionally validated? E.g. in a situation where a customer enters a wrong email by mistake, it will not be sent.

    Feel free to contact me if you have more questions.

    Thread Starter avinashdigitl

    (@avinashdigitl)

    Thanks i have figure it out using below code.

    function custom_order_email_recipient($recipient, $order)
    {
        if (!$order) {
            return;
        }
    
        $status = false;
        $email_send_user = '';
    
        foreach ($order->get_items() as $item_id => $item) {
            $is_gift = wc_get_order_item_meta($item_id, 'Is Gift?', true);
            $gift_user_email = wc_get_order_item_meta($item_id, 'Gift User Email', true);
    
            if ($is_gift == 'Yes' && !empty($gift_user_email)) {
                $status = true;
                $email_send_user = $gift_user_email;
            }
        }
    
        if ($status && !empty($email_send_user)) {
            $recipient = $email_send_user;
        }
    
        // Return the recipient
        return $recipient;
    }
    add_filter('woocommerce_email_recipient_customer_on_hold_order', 'custom_order_email_recipient', 10, 2);
    add_filter('woocommerce_email_recipient_customer_processing_order', 'custom_order_email_recipient', 20, 2);
    add_filter('woocommerce_email_recipient_customer_completed_order', 'custom_order_email_recipient', 30, 2);
    add_filter('woocommerce_email_recipient_customer_refunded_order', 'custom_order_email_recipient', 40, 2);
    Plugin Support rzepsen

    (@rzepsen)

    Oh,

    I see. Super that you managed the challenge. If you have additional questions, feel free to contact me again.

    Thread Starter avinashdigitl

    (@avinashdigitl)

    Hi, When i try to add product into cart using this type of link, then this plugin is giving error.

    ?add-to-cart=52008

    Error: The e-mail address provided is not valid for the?Gift User Email?field.

    Thread Starter avinashdigitl

    (@avinashdigitl)

    Hi @rzepsen,

    Can you advice on this ASAP, please?

    Thanks in advance.

    Plugin Support rzepsen

    (@rzepsen)

    Hi avinashdigitl

    Such a quick link will not work. Buying through the product page and the cart will work.

    It may work if you set the field to be optional. You also need to bypass validation, for the email field. Then the product will be added to the cart, but with an empty field. Is this the solution you would expect?

    Plugin Support rzepsen

    (@rzepsen)

    Hi avinashdigitl

    As we haven’t got any replies, I’m marking this topic as resolved for now.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to sent email to Field?’ is closed to new replies.