I want to stop woocommerce email notification if order value is $0.00
I used this code :
function restrict_admin_new_order_mail( $recipient, $order ) {
if( $order->get_total() === '0.00' ) {
return;
} else {
return $recipient;
}
}
add_filter('woocommerce_email_recipient_new_order', 'restrict_admin_new_order_mail', 1, 2);
The code working but I got this fatal error, all email options disappeared at Woocommerce settings (see attached screenshot).
Error Details
=============
[13-Jan-2021 17:34:15 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_total() on null in C:UsersjoeLocal Sitesstagingapppublicwp-contentthemesflatsome-childfunctions.php:8
Stack trace:
#0 C:UsersjoeLocal Sitesstagingapppublicwp-includesclass-wp-hook.php(289): restrict_admin_new_order_mail('email@gmail....', NULL)
#1 C:UsersjoeLocal Sitesstagingapppublicwp-includesplugin.php(206): WP_Hook->apply_filters('email@gmail....', Array)
#2 C:UsersjoeLocal Sitesstagingapppublicwp-contentpluginswoocommerceincludesemailsclass-wc-email.php(399): apply_filters('woocommerce_ema...', 'email@gmail....', NULL, Object(WC_Email_New_Order))
#3 C:UsersjoeLocal Sitesstagingapppublicwp-contentpluginswoocommerceincludesadminsettingsclass-wc-settings-emails.php(294): WC_Email->get_recipient()
#4 C:UsersjoeLocal Sitesstagingapppublicwp-includesclass-wp-hook.php(287): WC_Settings_Emails->email_notification_setting(Array)
#5 C:UsersjoeLocal Sitesstagingapppublicwp-includes in C:UsersjoeLocal Sitesstagingapppublicwp-contentthemesflatsome-childfunctions.php on line 8
Any help please?
Thanks
3
Answers
I removed (float) to make it work, this code stop notification email for admin
Take a look at.
You can target different emails woocommerce_email_recipient_customer_processing_order
To avoid this error, you need to add this simple line inside your function at the beginning:
I have also revisited your code a bit… Try this:
Code goes in functions.php file of the active child theme (or active theme). It should works now.