79597105

Date: 2025-04-28 18:40:52
Score: 2
Natty:
Report link

From your description and the provided screenshots, it's challenging to pinpoint the exact cause of your problem, because the issue can result from multiple possible issues. To effectively debug this, additional information would be helpful, such as:

However there are multiple problems that I can see in your code:
$emails['WC_Email_Customer_Doi_Xac_Nhan_Order'] = include get_stylesheet_directory() . '/woocommerce/emails/class-wc-email-customer-doi-xac-nhan-order.php';

This approach is incorrect because you're directly using include, which returns only a boolean (true) or the return statement from the included file—not the actual instantiated object you need for WooCommerce emails.

I would use it like this:

add_filter('woocommerce_email_classes', 'add_custom_order_status_emails');

function add_custom_order_status_emails($emails) {
    // Include your email class files
    require_once get_stylesheet_directory() . '/woocommerce/emails/class-wc-email-customer-doi-xac-nhan-order.php';
    require_once get_stylesheet_directory() . '/woocommerce/emails/class-wc-email-admin-da-cap-nhat.php';
    require_once get_stylesheet_directory() . '/woocommerce/emails/class-wc-email-customer-da-cap-nhat.php';

    // Properly instantiate each email class
    $emails['WC_Email_Customer_Doi_Xac_Nhan_Order'] = new WC_Email_Customer_Doi_Xac_Nhan_Order();
    $emails['WC_Email_Admin_Updated']               = new WC_Email_Admin_Updated();
    $emails['WC_Email_Customer_Updated']            = new WC_Email_Customer_Updated();

    return $emails;
}

// Trigger custom emails on order status change
add_action('woocommerce_order_status_changed', 'trigger_custom_order_email', 10, 4);

function trigger_custom_order_email($order_id, $old_status, $new_status, $order) {
    if ($new_status === 'doi-xac-nhan') {
        WC()->mailer()->emails['WC_Email_Customer_Doi_Xac_Nhan_Order']->trigger($order_id);
    }

    if ($new_status === 'da-cap-nhat') {
        WC()->mailer()->emails['WC_Email_Admin_Updated']->trigger($order_id);
        WC()->mailer()->emails['WC_Email_Customer_Updated']->trigger($order_id);
    }
}

WooCommerce expects e-mail specific CSS to be available in the following files:
your-theme-folder/woocommerce/emails/email-styles.php

Before doing a real test, you can test it in WooCommerce -> Settings -> Emails -> [Your Custom Email] -> View Template

Please let me know how you progress - and if you provide more information, it will be handled easily.

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know how you
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Mark