-
AuthorPosts
-
May 27, 2025 at 11:42 am #237155
蒼owoParticipantI have create the code that can support my custom order status
but my email log will say Message body empty
how do i fix it?// 1. Register custom Email Class for pending-contact
add_action(‘woocommerce_email_classes’, function($email_classes) {
error_log(‘[DEBUG] Entered woocommerce_email_classes hook’);
if (!class_exists(‘WC_Email_Customer_Pending_Contact_Order’)) {
class WC_Email_Customer_Pending_Contact_Order extends WC_Email {
public function __construct() {
error_log(‘[DEBUG] Constructing WC_Email_Customer_Pending_Contact_Order’);
$this->id = ‘customer_pending_contact_order’;
$this->title = ‘Pending Contact Order Notification (Customer)’;
$this->description = ‘Send to customer when order status is set to wc-pending-contact’;
$this->customer_email = true;
parent::__construct();
add_action(‘woocommerce_order_status_pending-contact’, [$this, ‘trigger’], 10, 2);
error_log(‘[DEBUG] add_action(woocommerce_order_status_pending-contact, trigger)’);
}
public function trigger($order_id, $order = false) {
error_log(‘[DEBUG] [PendingContact] trigger: order_id=’ . $order_id);
if (!$order && $order_id) $order = wc_get_order($order_id);
if (!$order) {
error_log(‘[ERROR] Failed to get order object’);
return;
}
$this->object = $order;
$this->recipient = $order->get_billing_email();
if ($this->is_enabled() && $this->get_recipient()) {
error_log(‘[SUCCESS] Sending mail to: ‘ . $this->get_recipient());
$this->send(
$this->get_recipient(),
$this->get_subject(),
$this->get_content(),
$this->get_headers(),
$this->get_attachments()
);
} else {
error_log(‘[ERROR] Email not enabled or recipient not found’);
}
}
// All content handled by WETC, leave blank
public function get_content_html() { error_log(‘[DEBUG] get_content_html called, expected to be handled by WETC’); return ”; }
public function get_content_plain() { error_log(‘[DEBUG] get_content_plain called, expected to be handled by WETC’); return ”; }
}
}
$email_classes[‘WC_Email_Customer_Pending_Contact_Order’] = new WC_Email_Customer_Pending_Contact_Order();
error_log(‘[DEBUG] Registered WC_Email_Customer_Pending_Contact_Order’);
return $email_classes;
}, 99);// 2. Register custom WooCommerce email action
add_filter(‘woocommerce_email_actions’, function($actions){
error_log(‘[DEBUG] Entered woocommerce_email_actions, added wc-pending-contact’);
$actions[] = ‘woocommerce_order_status_wc-pending-contact’;
return $actions;
});// 3. Register to WETC (VillaTheme) Email Template Customizer
add_filter(‘viwec_accept_email_type’, function($types) {
$types[] = ‘customer_pending_contact_order’;
error_log(‘[DEBUG] Added to viwec_accept_email_type: customer_pending_contact_order’);
return $types;
}, 9999);// 4. Failsafe: Always manually trigger email on status change or save
add_action(‘woocommerce_order_status_changed’, function($order_id, $old_status, $new_status, $order) {
error_log(“[DEBUG] Order status changed, order_id: $order_id, old_status: $old_status, new_status: $new_status”);
if ($new_status === ‘pending-contact’) {
do_action(‘woocommerce_order_status_pending-contact’, $order_id, $order);
error_log(“[DEBUG] Manually triggered woocommerce_order_status_pending-contact”);
}
}, 10, 4);add_action(‘save_post_shop_order’, function($post_id, $post, $update) {
$order = wc_get_order($post_id);
if (!$order) return;
$status = $order->get_status();
error_log(“[DEBUG] save_post_shop_order, post_id: $post_id, status: $status”);
if ($status === ‘pending-contact’) {
do_action(‘woocommerce_order_status_pending-contact’, $post_id, $order);
error_log(“[DEBUG] Manually triggered woocommerce_order_status_pending-contact via save_post_shop_order”);
}
}, 10, 3); -
AuthorPosts
You must be logged in to see replies to this topic. Click here to login or register