WooCommerce email IDs and order status change for email notifications

落爺英雄遲暮 提交于 2021-02-20 02:15:55

问题


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 call set_status()).



来源:https://stackoverflow.com/questions/51693276/woocommerce-email-ids-and-order-status-change-for-email-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!