【问题标题】:Trigger WooCommerce Email on Custom Order Actions在自定义订单操作上触发 WooCommerce 电子邮件
【发布时间】:2017-01-11 23:54:48
【问题描述】:

我整天都在试验并研究整个网络,但我似乎无法让这个动作起作用。 Basically I'm trying to trigger a Woo Email when a custom order action is selected.在这种情况下,它是一张礼品收据。

请注意:当我打开调试时,我得到一个headers already sent notice,当它关闭时没有。

这是我尝试过的代码:


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');

谢谢。

【问题讨论】:

    标签: wordpress email woocommerce


    【解决方案1】:
    function gift_receipt_wc_process_order_meta_box_action() 
    

    缺少$订单

    function gift_receipt_wc_process_order_meta_box_action($order) 
    

    这可能是问题吗?

    【讨论】:

    • 不,这似乎不起作用——我安装了一个邮件记录器,但它似乎没有发送电子邮件
    【解决方案2】:

    所以我在喝了更多咖啡后才想通。问题是 2 倍:

    1) 我没有将订单 ($order) 信息传递给函数 gift_receipt_wc_process_order_meta_box_action()

    2) 电子邮件的 ID(名称)实际上是 'wc_gift_order' 而不是 'wc_gift_order_email'

    感谢您的帮助!

    【讨论】:

      猜你喜欢
      • 2016-03-03
      • 2019-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      • 2019-08-11
      相关资源
      最近更新 更多