
In a recent Business Bloomer Club discussion, a member sought a way to highlight products that have recently returned to stock. When popular items come back, they often go unnoticed by customers unless they’re already on a wishlist.
The ideal solution would be to showcase restocked products using WooCommerce’s [products]
shortcode, but WooCommerce doesn’t natively track or display “back-in-stock” items. This article explores how to achieve a restock display functionality with hooks, custom fields, and product queries.
Step 1: Capture Restock Events with WooCommerce Hooks
To identify when a product is restocked, you’ll need to listen for stock updates. WooCommerce has hooks such as woocommerce_product_set_stock
that trigger when stock levels change. By checking if the stock status shifts from “out of stock” to “in stock,” you can record the restock date in a custom field.
Code Example
Here’s a basic snippet to update a custom field when a product is restocked:
add_action( 'woocommerce_product_set_stock_status', 'record_restock_date', 10, 3 );
function record_restock_date( $product_id, $stock_status, $product ) {
if ( 'instock' === $stock_status ) {
update_post_meta( $product_id, '_restock_date', current_time('mysql') );
}
}
This code will save the date when the stock status changes to “in stock.” With the _restock_date
custom field, you can then query products based on recent restocks.
Step 2: Query Recently Restocked Products
To display these products on the frontend, you can create a custom query to pull items with the Enable or disable WooCommerce payment methods based on cart product categories Add extra To:, CC:, and BCC: email recipients to any active WooCommerce email. Available placeholders: {customer}, {admin}. Enable or disable WooCommerce payment methods based on shipping method Add multiple items to the WooCommerce cart using customizable URLs Attach files to any WooCommerce email (PDFs, docs, images, and more) Show WooCommerce prices with and without tax Restrict WooCommerce Cart to one product Show only one dynamic price on WooCommerce variable product pages Enable or disable WooCommerce payment methods by billing or shipping location Enable or disable WooCommerce payment methods based on user role Redirect WooCommerce orders to a custom WordPress page Display stock availability on WooCommerce product archives Hide SKU, categories, and/or tags on WooCommerce product pages Ensure all rows in the WooCommerce Shop page have consistent height Disable purchases or display notices on your WooCommerce store while you’re away Show only billing name and email on the WooCommerce checkout for virtual orders Enable or disable WooCommerce shipping methods based on cart weight Add quantity inputs to WooCommerce Classic Checkout Boost SEO with a second description on WooCommerce category pages Add a prefix and/or suffix to all WooCommerce product prices Set orders to “Completed” status automatically based on product type (virtual, downlodable), product IDs, categories, tags, and more – skipping “Processing” entirely or conditionally. Display additional billing and shipping fields in the WooCommerce registration form Auto-update WooCommerce Cart totals when item quantities are changed Hide the product sorting dropdown on WooCommerce product archives. Add plus and minus buttons to WooCommerce quantity inputs Add custom content to the WooCommerce Thank You page via a WYSIWYG editor Add a “Billing Email” column to the WooCommerce Orders table, making it easier to filter and manage customer orders. Hide WooCommerce prices and add to cart buttons for logged out users Reposition the WooCommerce “Orders” menu item in the WordPress sidebar, making it easier for store managers to access and manage orders. Customize WooCommerce emails (colors, fonts, margins, etc.) with a CSS editor Customize the “Select options” button text on the WooCommerce Shop page Display the min or max variation price with optional prefix/suffix instead of the variable product price range. Automatically apply a coupon when a product or variation is added to cart Enable or disable WooCommerce payment methods based on cart total Generate WooCommerce sales reports by billing state for any year in seconds. Analyze regional revenue trends effortlessly. Easily remove or customize the “Added to your cart” message in WooCommerce to improve messaging and enhance the shopping experience. Move all out-of-stock products to the end of the classic shop, category, and loop pages when using the ‘Default sorting’ option. Remove specific tabs from the single product page, such as ‘Additional Information’, ‘Reviews’, and more. Align the Product Gallery to the side of the Single Product Page image_restock_date
field updated within a specific timeframe, like the last 7 days. Unfortunately, the
shortcode doesn’t support filtering by custom fields, so you’ll need to create a custom loop or modify the shortcode.
WooCommerce Toggle Payments By Category Mini-Plugin
$29.00 / once
WooCommerce Add To: Cc: Bcc: Email Recipients Mini-Plugin
$29.00 / once
WooCommerce Toggle Payments By Shipping Mini-Plugin
$29.00 / once
WooCommerce Add Multiple Products To Cart Via URL Mini-Plugin
$35.00 / once
WooCommerce Attach Files To Order Emails Mini-Plugin
$35.00 / once
WooCommerce Display Prices Including and Excluding Tax Mini-Plugin
$29.00 / once
WooCommerce Only Allow 1 Product in the Cart Mini-Plugin
$19.00 / once
WooCommerce Replace Variable Price With Active Variation Price Mini-Plugin
$25.00 / once
WooCommerce Toggle Payments By Country/State Mini-Plugin
$29.00 / once
WooCommerce Toggle Payments By User Role Mini-Plugin
$29.00 / once
WooCommerce Redirect To Custom Thank You Page Mini-Plugin
$19.00 / once
WooCommerce Display Stock Availability On The Shop Page Mini-Plugin
$19.00 / once
WooCommerce Hide Categories, Tags Or SKU on Single Product Mini-Plugin
$19.00 / once
WooCommerce Product Grid With Consistent Height Mini-Plugin
Original price was: $21.00.$10.50Current price is: $10.50. / once
WooCommerce Holiday Mode Mini-Plugin
$25.00 / once
WooCommerce Hide Checkout Fields For Virtual Products Mini-Plugin
$29.00 / once
WooCommerce Shipping By Weight Mini-Plugin
$27.00 / once
WooCommerce Change Product Quantity On The Checkout Page Mini-Plugin
$23.00 / once
WooCommerce Add Second Description To Product Category Pages Mini-Plugin
$29.00 / once
WooCommerce Add Prefix And Suffix to Product Prices Mini-Plugin
$19.00 / once
WooCommerce Autocomplete Orders Mini-Plugin
$0.00 / once
WooCommerce Add Customer Fields To My Account Registration Form Mini-Plugin
$39.00 / once
WooCommerce Automatically Update Cart On Quantity Change Mini-Plugin
$25.00 / once
WooCommerce Remove Default Sorting Dropdown Mini-Plugin
$15.00 / once
WooCommerce Add to Cart Quantity Plus & Minus Buttons Mini-Plugin
$19.00 / once
WooCommerce Add Content To The Thank You Page Mini-Plugin
$19.00 / once
WooCommerce Billing Email Column Mini-Plugin
$0.00 / once
WooCommerce Hide Price & Add to Cart If Logged Out Mini-Plugin
$25.00 / once
WooCommerce Move “Orders” Menu Item
$0.00 / once
WooCommerce Add CSS To Order Emails Mini-Plugin
$21.00 / once
WooCommerce Rename “Select Options” Button on Shop Page Mini-Plugin
$15.00 / once
WooCommerce Disable Variable Product Price Range Mini-Plugin
$21.00 / once
WooCommerce Auto Apply Coupon When Product Is Added to Cart Mini-Plugin
$19.00 / once
WooCommerce Toggle Payments By Cart Total Mini-Plugin
$23.00 / once
WooCommerce Sales By State Mini-Plugin
$39.00 / once
WooCommerce Remove / Edit “Added To Your Cart” Message Mini-Plugin
$18.00 / once
WooCommerce Show In Stock Products First Mini-Plugin
$19.00 / once
WooCommerce Remove Tabs From Single Product Page Mini-Plugin
$19.00 / once
WooCommerce Display Product Gallery Vertically Mini-Plugin
$19.00 / once
Custom Query Loop
$args = array(
'post_type' => 'product',
'posts_per_page' => 8,
'meta_key' => '_restock_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => '_restock_date',
'value' => date( 'Y-m-d', strtotime( '-7 days' ) ),
'compare' => '>=',
'type' => 'DATE'
)
)
);
$restocked_products = new WP_Query( $args );
Using this approach, you can pull the products that were recently restocked and display them on any page.
Final Thoughts
Implementing this solution allows customers to see newly restocked products, increasing visibility and potential sales. Although it requires custom code, it’s a flexible and efficient approach that brings restocked items front and center without relying solely on a wishlist.