Add doc for unhooking/removing WooCommerce email notifications snippet. (#39280)
* add doc for unhooking/removing WooCommerce email notifications. * Update snippet to follow snippet standards. Co-authored-by: Niels Lange <info@nielslange.de> * Update docs/snippets/unhook--remove-woocommerce-emails.md Co-authored-by: Niels Lange <info@nielslange.de> --------- Co-authored-by: Niels Lange <info@nielslange.de>
This commit is contained in:
parent
5b412c46f0
commit
565c8267de
|
@ -2,4 +2,5 @@
|
||||||
|
|
||||||
Various code snippets you can add to your site to enable custom functionality:
|
Various code snippets you can add to your site to enable custom functionality:
|
||||||
|
|
||||||
- [Add a message above the login / register form](./before-login--register-form.md)
|
- [Unhook and remove WooCommerce emails](./unhook--remove-woocommerce-emails.md);
|
||||||
|
- [Add a message above the login / register form](./before-login--register-form.md)
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
# Unhook and remove WooCommerce emails
|
||||||
|
|
||||||
|
> This is a **Developer level** doc. If you are unfamiliar with code and resolving potential conflicts, select a [WooExpert or Developer](https://woocommerce.com/customizations/) for assistance. We are unable to provide support for customizations under our [Support Policy](http://www.woocommerce.com/support-policy/).
|
||||||
|
|
||||||
|
This code allows you to unhook and remove the default WooCommerce emails.
|
||||||
|
|
||||||
|
Add this code to your child theme’s `functions.php` file or via a plugin that allows custom functions to be added, such as the [Code snippets](https://wordpress.org/plugins/code-snippets/) plugin. Avoid adding custom code directly to your parent theme’s `functions.php` file, as this will be wiped entirely when you update the theme.
|
||||||
|
|
||||||
|
```php
|
||||||
|
if ( ! function_exists( 'YOUR_PREFIX_unhook_woocommerce_emails' ) ) {
|
||||||
|
/**
|
||||||
|
* Callback for woocommerce_email action hook
|
||||||
|
*
|
||||||
|
* @param WC_Email $email_class An Email class instance.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function YOUR_PREFIX_unhook_woocommerce_emails( $email_class ) {
|
||||||
|
/**
|
||||||
|
* Hooks for sending emails during store events.
|
||||||
|
*/
|
||||||
|
remove_action( 'woocommerce_low_stock_notification', array( $email_class, 'low_stock' ) );
|
||||||
|
remove_action( 'woocommerce_no_stock_notification', array( $email_class, 'no_stock' ) );
|
||||||
|
remove_action( 'woocommerce_product_on_backorder_notification', array( $email_class, 'backorder' ) );
|
||||||
|
|
||||||
|
// New order emails.
|
||||||
|
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
||||||
|
remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
||||||
|
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
||||||
|
remove_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
||||||
|
remove_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
||||||
|
remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
||||||
|
|
||||||
|
// Processing order emails.
|
||||||
|
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
|
||||||
|
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger' ) );
|
||||||
|
|
||||||
|
// Completed order emails.
|
||||||
|
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
|
||||||
|
|
||||||
|
// Note emails.
|
||||||
|
remove_action( 'woocommerce_new_customer_note_notification', array( $email_class->emails['WC_Email_Customer_Note'], 'trigger' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'woocommerce_email', 'YOUR_PREFIX_unhook_woocommerce_emails' );
|
||||||
|
```
|
Loading…
Reference in New Issue