gpt4 book ai didi

php - 为 Woocommerce 中处于暂停状态的 COD 订单发送电子邮件通知

转载 作者:搜寻专家 更新时间:2023-10-31 21:20:43 27 4
gpt4 key购买 nike

我正在使用 wordpress 4.9.5 和 woocommerce 3.3.5,我想触发以下付款方式、订单状态和客户邮件。

  • Paypal = 完成 + 付款确认邮件
  • BACS = 暂停 + 订单暂停电子邮件
  • COD = 搁置 + 订单搁置电子邮件

此时一切正常,除了在使用 COD 时没有收到“订单暂停电子邮件”。订单状态为“待定”,但未发送待定邮件!

这是我使用的代码:

add_action( 'woocommerce_thankyou', 'wc_auto_complete_paid_order', 20, 1 );
function wc_auto_complete_paid_order( $order_id ) {
if ( ! $order_id )
return;

// Get an instance of the WC_Product object
$order = wc_get_order( $order_id );

// On hold status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
if ( in_array( $order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '' ) ) ) {
$order->update_status( 'on-hold' );
// Updated status to "completed" for paid Orders with all others payment methods
} else {
$order->update_status( 'completed' );
}
}

function unhook_new_order_processing_emails( $email_class ) {
// Turn off pending to processing for now
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
// Turn it back on but send the on-hold email
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger' ) );
}

最佳答案

首先,你的第二个函数中缺少钩子(Hook)......它应该是:

add_action( 'woocommerce_email', 'unhook_new_order_processing_emails' );
function unhook_new_order_processing_emails( $email_class ) {
// Turn off pending to processing for now
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
// Turn it back on but send the on-hold email
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger' ) );
}

官方文档:Unhook/remove WooCommerce Emails


然后要触发“货到付款”订单的“暂停”通知,您可以尝试以下操作:

// Trigger "On hold" notification for COD orders
add_action('woocommerce_order_status_on-hold', 'email_on_hold_notification_for_cod', 2, 20 );
function email_on_hold_notification_for_cod( $order_id, $order ) {
if( $order->get_payment_method() == 'cod' )
WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
}

代码进入您的事件子主题(或事件主题)的 function.php 文件..

关于php - 为 Woocommerce 中处于暂停状态的 COD 订单发送电子邮件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50336091/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com