问题
I am trying to add a function that will log any email that is sent through order status changes.
Is there a hook I can use that is triggered right before an order notification email is sent?
回答1:
Updated
All the available hooks responsible for triggering email notifications are located in WC_Emails init_transactional_emails() method and are action hooks:
woocommerce_low_stock
,woocommerce_no_stock
,woocommerce_product_on_backorder
,woocommerce_order_status_pending_to_processing
,woocommerce_order_status_pending_to_completed
,woocommerce_order_status_processing_to_cancelled
,woocommerce_order_status_pending_to_failed
,woocommerce_order_status_pending_to_on-hold
,woocommerce_order_status_failed_to_processing
,woocommerce_order_status_failed_to_completed
,woocommerce_order_status_failed_to_on-hold
,woocommerce_order_status_on-hold_to_processing
,woocommerce_order_status_on-hold_to_cancelled
,woocommerce_order_status_on-hold_to_failed
,woocommerce_order_status_completed
,woocommerce_order_fully_refunded
,woocommerce_order_partially_refunded
,woocommerce_new_customer_note
,woocommerce_created_customer
.
Each of those action hooks can queue or send transactional emails as you will see in the source code on line 95 or on line 99.
Last thing for the new order notification, which is a bit appart, you will use one of those:
woocommerce_order_status_pending_to_processing_notification
,woocommerce_order_status_pending_to_completed_notification
,woocommerce_order_status_pending_to_on-hold_notification
,woocommerce_order_status_failed_to_processing_notification
,woocommerce_order_status_failed_to_completed_notification
,woocommerce_order_status_failed_to_on-hold_notification
,
as documented in this WC_Email_New_Order code source.
Or you can detect status changes using one of the 3 hooks located in status_transition() WC_Order method:
woocommerce_order_status_changed
woocommerce_order_status_{$status_transition[from]}_to_{$status_transition[to]}
woocommerce_order_status_{$status_transition[to]}
The
status_transition()
is included in set_status() WC_Order method (and so also update_status() method too which callset_status()
).
来源:https://stackoverflow.com/questions/51693276/woocommerce-email-ids-and-order-status-change-for-email-notifications