Out-of-stock products don’t have to mean lost sales.
With a back-in-stock notification system, you can collect customer interest and bring them back when the product becomes available again.
In this tutorial, you will learn how to create a simple back-in-stock notification system using WooCommerce hooks.
Why This Feature Is Powerful
Instead of losing customers when a product is unavailable, you keep them engaged and ready to buy later.
- Recovers lost sales opportunities
- Builds email list automatically
- Improves customer retention
- Increases future conversions
The WooCommerce Hook We Will Use
We will use:
woocommerce_single_product_summary
This hook allows us to show a custom form on the product page.
Step 1: Show Notification Form
Add this code to your theme’s functions.php file or a custom plugin:
add_action('woocommerce_single_product_summary', 'back_in_stock_form', 30);
function back_in_stock_form() {
global $product;
if (!$product || $product->is_in_stock()) {
return;
}
echo '';
echo 'This product is currently out of stock.
';
echo 'Get notified when it becomes available again:
';
echo '';
echo '';
}
Step 2: Handle Form Submission
Now we capture the email submission:
add_action('init', 'handle_back_in_stock_submission');
function handle_back_in_stock_submission() {
if (!isset($_POST['restock_email'])) {
return;
}
$email = sanitize_email($_POST['restock_email']);
if (!is_email($email)) {
return;
}
// Here you can store email in database or send to CRM
update_option('restock_request_' . time(), $email);
}
How It Works
- Checks if product is out of stock
- Displays email subscription form
- Saves user email when submitted
Advanced Improvements
- Store emails per product ID
- Send automatic email when product restocks
- Integrate with Mailchimp or CRM
- Add double opt-in confirmation
