Many people ask me about how to send email notification to admin when new order is placed. By default, woocommerce only send out email when order payment is completed. But… thanks to Woocommerce team, they provide a lot of hooks to ease developer’s work. So we utilize the hook to do what we want.
Below is the code sample to send email notification to admin when new order is placed:-
Advertisements
- Open your functions.php
- Copy and paste the code below at the end of the functions.php
add_action( 'woocommerce_new_order', 'sogua_email_quote_pending', 20, 1 ); function sogua_email_quote_pending( $order_id ) { $order = wc_get_order( $order_id ); // if order is "pending" then continue if( ! $order->has_status( 'pending' ) ) return; $to = 'your-email@address.com'; $subject = 'New Quote'; $message = 'New Quote created at ' . date('Y-m-d H:i:s'); wp_mail( $to, $subject, $message ); }
- Save the file and you may try to create a new order and check if you receive the email notification.
* woocommerce_new_order hook will not return u any items details thru $order->get_items();
** You might also want to try woocommerce_checkout_order_processed hook, to get all the items
Related posts:
Woocommerce: Order Status Explanation
Woocommerce: Behaviour of each payment method during checkout
Woocommerce show product RSS feed by category and tags
How to add user custom field in My Account page in Woocommerce?
How to change shop title in Woocommerce
How to change 'Out of Stock' text in Woocommerce
Woocommerce: Coupon for new customer / first order only
Share this with your friends:-