在交易电子邮件中使用时,自定义状态更改上的 Woocommerce 挂钩不会触发
我无法收到有关状态更改的交易电子邮件。我在 woo commerce 插件上设置了自定义状态和自定义电子邮件,我根据自己的需要进行了编程。
该代码遵循与描述的 ootb 交易电子邮件相同的逻辑 此处
<?php
/*
Plugin Name: WooCommerce Custom Statuses
*/
if (!defined('ABSPATH')) {
return;
}
/**
* Class Custom_WC_Email
*/
class WC_LR_custom_order_statuses
{
/**
* Custom_WC_Email constructor.
*/
public function __construct()
{
// Filtering the emails and adding our own email.
add_filter('woocommerce_email_classes', array($this, 'lr_register_emails'), 10, 1);
add_filter('woocommerce_register_shop_order_post_statuses', [$this, 'lr_register_statuses'], 10, 1);
add_filter('wc_order_statuses', [$this, 'lr_custom_wc_order_statuses']);
add_filter('bulk_actions-edit-shop_order', [$this, 'lr_custom_dropdown_bulk_actions_shop_order'], 20, 1);
foreach (['post', 'shop_order'] as $hook)
add_filter("views_edit-$hook", [$this, 'lr_shop_order_modified_views']);
add_action('admin_head', [$this, 'lr_change_order_processing_row_color']);
//add_action('init', [$this, 'register_statuses']);
// add_action( 'add_meta_boxes', [$this,'littlerug_add_custom_box'] );
// add_action( 'save_post', [$this,'littlerug_save_postdata'], 1, 2 );
// Absolute path to the plugin folder.
define('CUSTOM_WC_EMAIL_PATH', plugin_dir_path(__FILE__));
}
function lr_shop_order_modified_views($views)
{
// if( isset( $views['wc-completed'] ) )
// $views['wc-completed'] = str_replace( 'Completed', __( 'Order Received', 'woocommerce'), $views['wc-completed'] );
if (isset($views['wc-processing']))
$views['wc-processing'] = str_replace('Spracováva sa', 'Čakajúce na platbu', $views['wc-processing']);
if (isset($views['wc-on-hold'])) {
if (preg_match('/Čaká/', $views['wc-on-hold']))
$views['wc-on-hold'] = str_replace('Čaká', 'Prijatá', $views['wc-on-hold']);
else
$views['wc-on-hold'] = str_replace('Čakajúce', 'Prijaté', $views['wc-on-hold']);
}
// if( isset( $views['wc-pending'] ) )
// $views['wc-pending'] = str_replace( 'Pending', __( 'Stucked', 'woocommerce'), $views['wc-pending'] );
return $views;
}
function lr_custom_dropdown_bulk_actions_shop_order($actions)
{
unset($actions['mark_processing']);
unset($actions['mark_pending']);
unset($actions['mark_cancelled']);
unset($actions['mark_completed']);
$actions['mark_on-hold'] = 'Zmeniť stav na "Prijatá"';
$actions['mark_order-confirmed'] = 'Zmeniť stav na "Potvrdená"';
$actions['mark_payment-await'] = 'Zmeniť stav na "Čaká na platbu"';
$actions['mark_payment-received'] = 'Zmeniť stav na "Platba prijatá"';
$actions['mark_order-shipped'] = 'Zmeniť stav na "Odoslaná"';
$actions['mark_completed'] = 'Zmeniť stav na "Vybavená"';
$actions['mark_order-done'] = 'Zmeniť stav na "Hotová"';
$actions['mark_cancelled'] = 'Zmeniť stav na "Zrušená"';
return $actions;
}
function lr_change_order_processing_row_color()
{
echo sprintf(
'
<style type="text/css">
.order-status.status-order-shipped {
background: #c8d7e1;
color: #2e4453;
}
.order-status.status-order-confirmed {
background: #edc77a;
color: #a36e03;
}
.order-status.status-payment-received {
background: #8cd98c;
color: #507418;
}
.order-status.status-order-done {
background: #fdfd96;
color: #8f8f12;
}.order-status.status-payment-await {
background: #c6e1c6;
color: #5b841b;
}
</style>'
);
}
function lr_custom_wc_order_statuses($order_statuses)
{
//change default status names add new
unset($order_statuses['wc-processing']);
unset($order_statuses['wc-pending']);
unset($order_statuses['wc-completed']);
unset($order_statuses['wc-cancelled']);
unset($order_statuses['wc-refunded']);
unset($order_statuses['wc-failed']);
$order_statuses['wc-on-hold'] = _x('Prijatá', 'woocommerce');
$order_statuses['wc-order-confirmed'] = _x('Potvrdená', 'Order status', 'woocommerce');
$order_statuses['wc-payment-await'] = _x('Čaká na platbu', 'woocommerce');
$order_statuses['wc-payment-received'] = _x('Platba prijatá', 'Order status', 'woocommerce');
$order_statuses['wc-order-shipped'] = _x('Odoslaná', 'Order status', 'woocommerce');
$order_statuses['wc-completed'] = _x('Vybavená', 'Order status', 'woocommerce');
$order_statuses['wc-order-done'] = _x('Hotová', 'Order status', 'woocommerce');
$order_statuses['wc-cancelled'] = _x('Zrušená', 'Order status', 'woocommerce');
$order_statuses['wc-refunded'] = _x('Refundovaná', 'Order status', 'woocommerce');
return $order_statuses;
}
/**
* @param array $emails
*
* @return array
*/
public function lr_register_emails($emails)
{
$emails['WC_Customer_Cancel_Order'] = include __DIR__ . '/emails/class-wc-customer-cancel-order.php';
$emails['WC_Customer_Payment_Received'] = include __DIR__ . '/emails/class-wc-customer-payment-received.php';
$emails['WC_Customer_Order_Shipped'] = include __DIR__ . '/emails/class-wc-customer-order-shipped.php';
$emails['WC_Customer_Order_Confirmed'] = include __DIR__ . '/emails/class-wc-customer-order-confirmed.php';
$emails['WC_Customer_Payment_Await'] = include __DIR__ . '/emails/class-wc-customer-payment-await.php';
//customer_processing_order
// $emails['WC_Customer_Order_Placed'] = new WC_Customer_Order_Placed();
return $emails;
}
public function lr_register_statuses($order_statuses)
{
// Status must start with "wc-"
$order_statuses['wc-payment-await'] = array(
'label' => 'Čaká na platbu', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Čaká na platbu <span class="count">(%s)</span>', 'Čaká na platbu <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-payment-received'] = array(
'label' => 'Platba prijatá', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Platba prijatá <span class="count">(%s)</span>', 'Platieb prijatých <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-order-shipped'] = array(
'label' => 'Odoslaná', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Odoslaná <span class="count">(%s)</span>', 'Odoslané <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-order-confirmed'] = array(
'label' => 'Potvrdená', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Potvrdená <span class="count">(%s)</span>', 'Potvrdené <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-order-done'] = array(
'label' => 'Hotová', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Hotová <span class="count">(%s)</span>', 'Hotové <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
return $order_statuses;
}
}
new WC_LR_custom_order_statuses();
此处描述了相同的问题,但我是在不使用 wc- 前缀的状态下正确执行此操作,
我们将非常感谢任何有关如何调试此问题的建议。
I am unable to get transactional email on status change. I have custom statuses and custom emails set on woo commerce plugin I programmed to my needs.
The code follows same logic as for ootb transactional emails described here
<?php
/*
Plugin Name: WooCommerce Custom Statuses
*/
if (!defined('ABSPATH')) {
return;
}
/**
* Class Custom_WC_Email
*/
class WC_LR_custom_order_statuses
{
/**
* Custom_WC_Email constructor.
*/
public function __construct()
{
// Filtering the emails and adding our own email.
add_filter('woocommerce_email_classes', array($this, 'lr_register_emails'), 10, 1);
add_filter('woocommerce_register_shop_order_post_statuses', [$this, 'lr_register_statuses'], 10, 1);
add_filter('wc_order_statuses', [$this, 'lr_custom_wc_order_statuses']);
add_filter('bulk_actions-edit-shop_order', [$this, 'lr_custom_dropdown_bulk_actions_shop_order'], 20, 1);
foreach (['post', 'shop_order'] as $hook)
add_filter("views_edit-$hook", [$this, 'lr_shop_order_modified_views']);
add_action('admin_head', [$this, 'lr_change_order_processing_row_color']);
//add_action('init', [$this, 'register_statuses']);
// add_action( 'add_meta_boxes', [$this,'littlerug_add_custom_box'] );
// add_action( 'save_post', [$this,'littlerug_save_postdata'], 1, 2 );
// Absolute path to the plugin folder.
define('CUSTOM_WC_EMAIL_PATH', plugin_dir_path(__FILE__));
}
function lr_shop_order_modified_views($views)
{
// if( isset( $views['wc-completed'] ) )
// $views['wc-completed'] = str_replace( 'Completed', __( 'Order Received', 'woocommerce'), $views['wc-completed'] );
if (isset($views['wc-processing']))
$views['wc-processing'] = str_replace('Spracováva sa', 'Čakajúce na platbu', $views['wc-processing']);
if (isset($views['wc-on-hold'])) {
if (preg_match('/Čaká/', $views['wc-on-hold']))
$views['wc-on-hold'] = str_replace('Čaká', 'Prijatá', $views['wc-on-hold']);
else
$views['wc-on-hold'] = str_replace('Čakajúce', 'Prijaté', $views['wc-on-hold']);
}
// if( isset( $views['wc-pending'] ) )
// $views['wc-pending'] = str_replace( 'Pending', __( 'Stucked', 'woocommerce'), $views['wc-pending'] );
return $views;
}
function lr_custom_dropdown_bulk_actions_shop_order($actions)
{
unset($actions['mark_processing']);
unset($actions['mark_pending']);
unset($actions['mark_cancelled']);
unset($actions['mark_completed']);
$actions['mark_on-hold'] = 'Zmeniť stav na "Prijatá"';
$actions['mark_order-confirmed'] = 'Zmeniť stav na "Potvrdená"';
$actions['mark_payment-await'] = 'Zmeniť stav na "Čaká na platbu"';
$actions['mark_payment-received'] = 'Zmeniť stav na "Platba prijatá"';
$actions['mark_order-shipped'] = 'Zmeniť stav na "Odoslaná"';
$actions['mark_completed'] = 'Zmeniť stav na "Vybavená"';
$actions['mark_order-done'] = 'Zmeniť stav na "Hotová"';
$actions['mark_cancelled'] = 'Zmeniť stav na "Zrušená"';
return $actions;
}
function lr_change_order_processing_row_color()
{
echo sprintf(
'
<style type="text/css">
.order-status.status-order-shipped {
background: #c8d7e1;
color: #2e4453;
}
.order-status.status-order-confirmed {
background: #edc77a;
color: #a36e03;
}
.order-status.status-payment-received {
background: #8cd98c;
color: #507418;
}
.order-status.status-order-done {
background: #fdfd96;
color: #8f8f12;
}.order-status.status-payment-await {
background: #c6e1c6;
color: #5b841b;
}
</style>'
);
}
function lr_custom_wc_order_statuses($order_statuses)
{
//change default status names add new
unset($order_statuses['wc-processing']);
unset($order_statuses['wc-pending']);
unset($order_statuses['wc-completed']);
unset($order_statuses['wc-cancelled']);
unset($order_statuses['wc-refunded']);
unset($order_statuses['wc-failed']);
$order_statuses['wc-on-hold'] = _x('Prijatá', 'woocommerce');
$order_statuses['wc-order-confirmed'] = _x('Potvrdená', 'Order status', 'woocommerce');
$order_statuses['wc-payment-await'] = _x('Čaká na platbu', 'woocommerce');
$order_statuses['wc-payment-received'] = _x('Platba prijatá', 'Order status', 'woocommerce');
$order_statuses['wc-order-shipped'] = _x('Odoslaná', 'Order status', 'woocommerce');
$order_statuses['wc-completed'] = _x('Vybavená', 'Order status', 'woocommerce');
$order_statuses['wc-order-done'] = _x('Hotová', 'Order status', 'woocommerce');
$order_statuses['wc-cancelled'] = _x('Zrušená', 'Order status', 'woocommerce');
$order_statuses['wc-refunded'] = _x('Refundovaná', 'Order status', 'woocommerce');
return $order_statuses;
}
/**
* @param array $emails
*
* @return array
*/
public function lr_register_emails($emails)
{
$emails['WC_Customer_Cancel_Order'] = include __DIR__ . '/emails/class-wc-customer-cancel-order.php';
$emails['WC_Customer_Payment_Received'] = include __DIR__ . '/emails/class-wc-customer-payment-received.php';
$emails['WC_Customer_Order_Shipped'] = include __DIR__ . '/emails/class-wc-customer-order-shipped.php';
$emails['WC_Customer_Order_Confirmed'] = include __DIR__ . '/emails/class-wc-customer-order-confirmed.php';
$emails['WC_Customer_Payment_Await'] = include __DIR__ . '/emails/class-wc-customer-payment-await.php';
//customer_processing_order
// $emails['WC_Customer_Order_Placed'] = new WC_Customer_Order_Placed();
return $emails;
}
public function lr_register_statuses($order_statuses)
{
// Status must start with "wc-"
$order_statuses['wc-payment-await'] = array(
'label' => 'Čaká na platbu', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Čaká na platbu <span class="count">(%s)</span>', 'Čaká na platbu <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-payment-received'] = array(
'label' => 'Platba prijatá', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Platba prijatá <span class="count">(%s)</span>', 'Platieb prijatých <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-order-shipped'] = array(
'label' => 'Odoslaná', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Odoslaná <span class="count">(%s)</span>', 'Odoslané <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-order-confirmed'] = array(
'label' => 'Potvrdená', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Potvrdená <span class="count">(%s)</span>', 'Potvrdené <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
$order_statuses['wc-order-done'] = array(
'label' => 'Hotová', //_x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Hotová <span class="count">(%s)</span>', 'Hotové <span class="count">(%s)</span>', 'woocommerce') //_n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
);
return $order_statuses;
}
}
new WC_LR_custom_order_statuses();
Same issue was described here but I am doing it correctly with the statuses not using wc- prefix
Any advice how to debug this issue would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现我需要添加电子邮件操作。不知道为什么,没有看到任何与此相关的文档,但这就是断点:)
在具有与上面相同的操作挂钩名称的扩展电子邮件开始触发并且电子邮件已成功发送之后。
Found out that I needed to add email actions. No idea why, did not see any documentation around this but this was the breaking point :)
After the extended email with the action hook names same as above started to trigger and email was sent successfully.