Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在WooCommerce中更改自定义订单状态时发送电子邮件通知_Php_Wordpress_Woocommerce_Orders_Email Notifications - Fatal编程技术网

Php 在WooCommerce中更改自定义订单状态时发送电子邮件通知

Php 在WooCommerce中更改自定义订单状态时发送电子邮件通知,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,我已在我的WooCommerce中创建了一个自定义订单状态,称为“Back order”(wc backorder): 当订单变为“延期订单”状态时,不会发生任何情况 有什么想法吗 我尝试了很多不同的钩子,但似乎无法运行触发器函数 我正在使用WordPress和WooCommerce(3.0+)的最新版本 谢谢 试试这个-EDIT/UPDATE- 由于您正在使用的代码教程对于新的mega major版本3.0+来说已经过时(2013年),因此此自定义函数在woocommerce\u order\

我已在我的WooCommerce中创建了一个自定义订单状态,称为“Back order”(
wc backorder
):

当订单变为“延期订单”状态时,不会发生任何情况

有什么想法吗

我尝试了很多不同的钩子,但似乎无法运行触发器函数

我正在使用WordPress和WooCommerce(3.0+)的最新版本

谢谢


试试这个

-EDIT/UPDATE-

由于您正在使用的代码教程对于新的mega major版本3.0+来说已经过时(2013年),因此此自定义函数在
woocommerce\u order\u status\u changed
action hook中挂钩将完成此任务。因此,当订单状态更改为自定义状态时,您将能够发送自定义处理电子邮件通知

以下是WC 3.0+的工作和测试代码:

add_action('woocommerce_order_status_changed', 'backorder_status_custom_notification', 10, 4);
function backorder_status_custom_notification( $order_id, $from_status, $to_status, $order ) {

   if( $order->has_status( 'backorder' )) {

        // Getting all WC_emails objects
        $email_notifications = WC()->mailer()->get_emails();

        // Customizing Heading and subject In the WC_email processing Order object
        $email_notifications['WC_Email_Customer_Processing_Order']->heading = __('Your processing Back order','woocommerce');
        $email_notifications['WC_Email_Customer_Processing_Order']->subject = 'Your {site_title} processing Back order receipt from {order_date}';

        // Sending the customized email
        $email_notifications['WC_Email_Customer_Processing_Order']->trigger( $order_id );
    }

}
这段代码位于活动子主题(或主题)的function.php文件或任何插件文件中


由于您的自定义状态是
wc backorder
,但不是
wc order confirmed
,您只需将所有
wc order confirmed
替换为
wc backorder

要使其工作,您必须以这种方式更改最后两个钩住的函数:

add_action( 'woocommerce_order_status_wc-backorder', array( WC(), 'send_transactional_email' ), 10, 1 );


add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
    $actions[] = 'woocommerce_order_status_wc-backorder';
    return $actions;
}
代码位于活动子主题(或主题)的function.php文件或任何插件文件中

这应该可以(我无法测试它,因为没有自定义插件的代码)



参考源代码:

如何在此功能中添加电子邮件页眉和页脚我添加了此挂钩,但当将状态更改为延期交货时,电子邮件不会进入customer@sarun没有人可以测试你的代码,因为你没有完全给出它。您应该需要添加一个外部链接到您的插件源代码…还请让我们知道您使用的是哪个版本的WooCommerce。此链接包含我的插件代码和functions.php代码
add_action("woocommerce_order_status_changed", "my_custom_notification");

function my_custom_notification($order_id, $checkout=null) {
   global $woocommerce;
   $order = new WC_Order( $order_id );
   if($order->status === 'backorder' ) {
      // Create a mailer
      $mailer = $woocommerce->mailer();

      $message_body = __( 'Hello world!!!' );

      $message = $mailer->wrap_message(
        // Message head and message body.
        sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message_body );

      // Cliente email, email subject and message.
     $mailer->send( $order->billing_email, sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message );
     }

   }
add_action('woocommerce_order_status_changed', 'backorder_status_custom_notification', 10, 4);
function backorder_status_custom_notification( $order_id, $from_status, $to_status, $order ) {

   if( $order->has_status( 'backorder' )) {

        // Getting all WC_emails objects
        $email_notifications = WC()->mailer()->get_emails();

        // Customizing Heading and subject In the WC_email processing Order object
        $email_notifications['WC_Email_Customer_Processing_Order']->heading = __('Your processing Back order','woocommerce');
        $email_notifications['WC_Email_Customer_Processing_Order']->subject = 'Your {site_title} processing Back order receipt from {order_date}';

        // Sending the customized email
        $email_notifications['WC_Email_Customer_Processing_Order']->trigger( $order_id );
    }

}
add_action( 'woocommerce_order_status_wc-backorder', array( WC(), 'send_transactional_email' ), 10, 1 );


add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
    $actions[] = 'woocommerce_order_status_wc-backorder';
    return $actions;
}