从订阅付款中触发woocommerce订单电子邮件挂钩 [英] Trigger woocommerce order email hook from subscription payment

查看:132
本文介绍了从订阅付款中触发woocommerce订单电子邮件挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在下达新订单时挂接到订阅插件,我已成功使用此操作完成了此操作: woocommerce_checkout_subscription_created.在该操作的功能内,我想修改发给客户的电子邮件,我尝试这样做:

I'd like to hook into the subscription plugin when a new order has been placed which I have done successfully using this action: woocommerce_checkout_subscription_created. Inside the function for that action I want to modify the email that goes out to the customer which I have tried to do like so:

<?php 
    function subscription_created($subscription){   

    add_action('woocommerce_email_before_order_table','my_offer',20);
    $order = $subscription->order;

    function my_offer($order){

        echo "<h2>Your Trial Offer</h2>";
        echo "<p>Your subscription to this product entitles you to a free blah blah blah...</p>";

    }

    return $var;

}
add_action('woocommerce_checkout_subscription_created','subscription_created'); 
?>

就像我说的那样,将触发创建的订阅的操作(我成功记录了$subscription的输出).电子邮件操作不起作用.

Like I said, the action for the created subscription fires (I logged the output for $subscription successfully). The email action isn't working.

我猜想这与范围有关,但是我不确定.任何想法将不胜感激.

I'm guessing this has something to do with scope, but I'm not sure. Any thoughts would be appreciated.

推荐答案

无法在一个动作中运行一个动作.

Running an action within an action isn't possible, I believe.

如果您查看此操作的代码,则可以访问以下内容:

If you check the code for this action, you have access to the following:

do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email );

因此,您可能无法挂接到woocommerce_checkout_subscription_created,而只能使用woocommerce_email_before_order_table.

Therefore, you could perhaps NOT hook into woocommerce_checkout_subscription_created and only use woocommerce_email_before_order_table.

然后您可以查询$order是否为订阅,然后相应地修改输出.

You could then query whether or not the $order is a subscription and then modify the output accordingly.

add_action( 'woocommerce_email_before_order_table', function($order, $sent_to_admin, $plain_text, $email) {
    if ( function_exists( 'wcs_order_contains_subscription' ) ) {
        if ( wcs_order_contains_subscription( $order->ID ) ) {
            // Do what you need to do
        }
    } 
}, 10, 4 );

这篇关于从订阅付款中触发woocommerce订单电子邮件挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆