I'm trying to develop a snippet in order to hide out-of-stock products after 10 days when they went sold out.
I'm trying to develop a snippet to hide out-of-stock products after 10 days when they sold out.
For that I was inspired by:
- Hide 'out of stock' products in Woocommerce
- Change stock email notifications recipient in WooCommerce
I have to build a custom function which will check the out of stock date. But I do not find any value or properties, which stores that date and time on which the product was marked as sold out.
Is there something out of the box available or do I have to create a snipped first to store the date and time when a product is marked as sold out and use that info with a IF statement to hide a product or not based on the days in between.
add_action('woocommerce_product_query', 'custom_woocommerce_product_query');
function custom_woocommerce_product_query($q)
{
if ( out_of_stock < 10 ())
{
$oos_query = new WP_Query(['meta_query' => [['key' => '_stock_status', 'value' => 'outofstock', 'compare' => '=', ], ], 'post_type' => 'product', 'posts_per_page' => - 1, 'fields' => 'ids', ]);
$exclude_ids = $oos_query->posts;
$q->set('post__not_in', $exclude_ids);
}
}
Out of the box "no stock" notification hook
add_filter( 'woocommerce_email_recipient_no_stock', 'change_stock_email_recipient', 10, 2 ); // For No stock notification
Would be glad if someone could point me in the right direction