Enhancing your store’s notification system can significantly streamline your order management process. One effective way to ensure you never miss a new order is by setting up a custom admin email notification for every new WooCommerce order. In this post, you’ll learn how to implement a solution that sends you an email each time a customer places an order. Whether you’re running a busy online store or just want to stay informed, this method ensures critical updates land directly in your inbox. Tools like WP Code or Code Snippets are recommended to safely add custom code without editing WooCommerce core files.
Using PHP hooks provided by WooCommerce, you can trigger an email notification whenever a new order is created. WooCommerce supplies the woocommerce_new_order
hook, which is fired as soon as a new order is recorded. By combining this hook with WordPress’s wp_mail()
function, you can craft a custom email notification that includes essential order details.
<?php
// Send a custom admin email notification when a new WooCommerce order is created
function send_custom_admin_email_for_order( $order_id ) {
// Retrieve the order details
$order = wc_get_order( $order_id );
// Get the site administrator's email address from settings
$admin_email = get_option( 'admin_email' );
// Define the email subject and message body
$subject = 'New WooCommerce Order Received';
$message = "Hello Admin,\n\n";
$message .= "A new order has been placed on your WooCommerce store.\n";
$message .= "Order ID: " . $order_id . "\n";
$message .= "Order Total: " . $order->get_formatted_order_total() . "\n\n";
$message .= "To view the full details of this order, please log in to your admin dashboard.\n\n";
$message .= "Best regards,\nYour WooCommerce Store";
// Use wp_mail to send the email
wp_mail( $admin_email, $subject, $message );
}
add_action( 'woocommerce_new_order', 'send_custom_admin_email_for_order' );
?>
The code above hooks into WooCommerce’s woocommerce_new_order
action, ensuring that every time a new order is placed, the function send_custom_admin_email_for_order
is executed. This function gathers key order details—such as the order ID and total amount—and formats them into a clear email message. The wp_mail()
function then sends this notification to the email address specified in your site’s settings. Tools like WP Code or Code Snippets help integrate this code effortlessly, keeping your core files untouched.
Depending on your needs, you might consider additional enhancements:
Setting up custom admin email notifications for every new WooCommerce order is a practical measure to ensure you remain promptly informed of all sales activities. By leveraging the woocommerce_new_order
hook and WordPress’s wp_mail()
function, you can easily create a system that sends detailed notifications to your admin email. Not only does this reduce the risk of missing new orders, but it also enhances your overall store management strategy. Experiment with the setup, refine the message content as needed, and enjoy a more responsive and efficient order management process.
Take the step towards better order visibility, and let your WooCommerce store work smarter for you!