0
votes

I have been experimenting all day and researching the whole web, and I cant seem to get this action to work. Basically I'm trying to trigger a Woo Email when a custom order action is selected. In this case, its a gift receipt.

Please Note: When I turn on debugging, I get a headers already sent notice, none when its off.

Here is the code which I had tried:


function gift_receipt_add_order_meta_box_action($actions)
{
    global $theorder;

    $actions['send_gift_receipt'] = __('Send Gift Receipt', 'enyc');
    return $actions;
}

add_action('woocommerce_order_actions', 'gift_receipt_add_order_meta_box_action');

function gift_receipt_wc_process_order_meta_box_action()
{

    $mailer = WC()->mailer();
    $mails = $mailer->get_emails();
    if (!empty($mails))
    {
        foreach ($mails as $mail)
        {
            if ($mail->id == 'wc_gift_order_email')
            {
                $mail->trigger($order->id);
            }
        }
    }
}

add_action('woocommerce_order_action_send_gift_receipt', 'gift_receipt_wc_process_order_meta_box_action');

Thanks.

2

2 Answers

0
votes
function gift_receipt_wc_process_order_meta_box_action() 

is missing $order

function gift_receipt_wc_process_order_meta_box_action($order) 

might this be the issue?

0
votes

So I figured it out after some more coffee. The problem was 2 fold:

1) I did not pass the order ($order) info to the function gift_receipt_wc_process_order_meta_box_action()

2) the id (name) of the email was actually 'wc_gift_order' instead of 'wc_gift_order_email'

Thanks for the help!