Загрузка...

How to Disable WooCommerce New Order Email Notification for Non-Pickup Orders

Discover how to customize WooCommerce notifications by disabling the new order email when the shipping method is not "Local Pickup." Follow our step-by-step guide!
---
This video is based on the question https://stackoverflow.com/q/68164986/ asked by the user 'agreenbow' ( https://stackoverflow.com/u/16334941/ ) and on the answer https://stackoverflow.com/a/68167748/ provided by the user '7uc1f3r' ( https://stackoverflow.com/u/11987538/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Disable WooCommerce new order email notification when shipping method is NOT "Local Pickup"

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/licensing
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Disabling WooCommerce New Order Email Notification for Non-Pickup Orders

If you run an online store using WooCommerce, you might want to streamline your email notifications, especially for different shipping methods. One common scenario is disabling the new order email notification when customers choose any shipping method other than "Local Pickup." This desire can arise from various operational needs, such as reducing unnecessary emails to staff when items aren't being picked up in-store.

In this guide, we will guide you on how to achieve that by using a simple filter in your WooCommerce setup.

The Challenge: Customizing Email Notifications

The challenge you're facing is that WooCommerce sends out a new order email notification for every order placed. However, you want to customize this behavior so that these notifications are only triggered when the "Local Pickup" option is selected at checkout. Your initial approach was to modify the woocommerce_email_enabled_new_order filter, but it seems there was some confusion regarding its implementation.

The Solution: Using a Different Filter

While your initial thought was on the right track, there's a more effective filter to use: woocommerce_email_recipient_new_order. This filter allows you to directly control the recipient of the new order email based on the shipping method selected.

Here’s How to Implement the Solution:

Remove the Old Filter: You won't need to modify the old filter you were using any further. Instead, you'll define a new one.

Building the Function: Use the following code snippet in your theme’s functions.php file or a custom plugin. This function will check the shipping method and determine if the email should be sent.

[[See Video to Reveal this Text or Code Snippet]]

Code Breakdown:

Function Definition: The function filter_woocommerce_email_recipient_new_order takes two parameters: $recipient, which holds the email address of the recipient, and $order, which is the order object.

Order Validation: The first if condition checks whether the order exists and is an instance of the WC_Order class—ensuring that we’re working with a valid WooCommerce order.

Shipping Method Check: Retrieve the shipping method using $order->get_shipping_method().

Set Recipient Based on Condition: If the shipping method is anything other than "Local Pickup," we set $recipient to an empty string, effectively disabling the email.

Implement and Test: After including the code, test different scenarios in your WooCommerce store by placing orders with different shipping methods. Verify that the notification only triggers for "Local Pickup" orders.

Conclusion

Disabling email notifications for non-pickup orders can enhance your store's efficiency and reduce clutter in your inbox. By following the straightforward approach outlined above, you can customize your WooCommerce email notifications to fit your operational needs efficiently. Implement this solution today and streamline your order notification process!

If you have any questions or run into issues while implementing this solution, feel free to drop a comment below! Happy selling!

Видео How to Disable WooCommerce New Order Email Notification for Non-Pickup Orders канала vlogize
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять