php - Send an Email notification to the admin for pending order status in WooCommerce -
in woocommerce, when customer goes checkout cart , submit order, if payment not processed, order set "pending" payment. admin doesn't received email about.
i send email admin kind of orders. how can it?
normally in woocommerce settings > emails, if "new order" email notification enabled, admin should receive notification new orders (whatever status)...
here, based on new order email notification (sent admin) after order has been submitted in checkout, function send customizable email notification admin targetting 'pending' or 'on-hold' order statuses (you can keep 'pending' if want) :
add_action( 'woocommerce_thankyou', 'custom_email_notification', 10, 1 ); function custom_email_notification( $order_id ) { if ( ! $order_id ) return; ## order data ## // instance of wc_order object $order = wc_get_order( $order_id ); // targetting order status 'pending' or 'on-hold' if( $order->has_status( 'pending' ) || $order->has_status( 'on-hold' ) ) { // getting wc_emails objects $wc_email_notifications = wc()->mailer()->get_emails(); // new email notification (admin) $email_object = $wc_email_notifications['wc_email_new_order']; // customizing heading, subject, recipients, email type … $email_object->settings = array( 'enabled' => 'yes', 'recipient' => 'name@email.com', // set here recipients emails (separated coma) 'subject' => '[{site_title}] new customer order ({order_number}) - {order_date}', 'heading' => 'new customer order', 'email_type' => 'html' ); // sending email $email_object->trigger( $order_id ); } }
code goes in function.php file of active child theme (or theme) or in plugin file.
this code tested , works in woocommerce versions 2.6.x , 3+.
you can customize email heading, subject, recipients , email type.
Comments
Post a Comment