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.
My Answer:
To debug this issue, you can try the following steps:
1. Check if the custom status change hook is working correctly outside of the transactional email. You can add some debug statements or log messages to see if the hook is being triggered when the status changes.
2. Make sure that the custom status change hook is correctly implemented and registered in your code. Double-check the hook name and the function that is supposed to be triggered when the status changes.
3. Check if the custom email classes are correctly registered and loaded in your code. Make sure that the email classes are properly included and instantiated when the status changes.
4. Verify that the custom email templates are correctly set up and configured in WooCommerce. Make sure that the email templates are associated with the custom statuses and are set to be sent when the status changes.
5. Check if there are any conflicts with other plugins or themes that may be affecting the email sending process. Disable any other plugins or themes temporarily to see if the issue persists.
6. If none of the above steps resolve the issue, you may need to reach out to WooCommerce support or forums for further assistance. They may be able to provide more specific guidance on debugging custom status change hooks in transactional emails.
Rate this post
4 of 5 based on 8274 votesComments