With woocommerce, I used some code based on my previous thread:
Allow backorders and notify customer for specific product categories in Woocommerce
add_filter( 'woocommerce_product_is_in_stock', 'filter_product_is_in_stock', 10, 2 );
function filter_product_is_in_stock( $is_in_stock, $product ){
// Here set the products categories in the array (can be terms ids, slugs or names)
$categories = array("clothing");
if( has_term( $categories, 'product_cat', $product->get_id() ) ){
$is_in_stock = true;
}
return $is_in_stock;
}
add_filter( 'woocommerce_product_backorders_allowed', 'filter_products_backorders_allowed', 10, 3 );
function filter_products_backorders_allowed( $backorder_allowed, $product_id, $product ){
// Here set the products categories in the array (can be terms ids, slugs or names)
$categories = array("clothing");
if( has_term( $categories, 'product_cat', $product_id ) ){
$backorder_allowed = true;
}
return $backorder_allowed;
}
add_filter( 'woocommerce_product_backorders_require_notification', 'filter_product_backorders_require_notification', 10, 2 );
function filter_product_backorders_require_notification( $notify, $product ){
// Here set the products categories in the array (can be terms ids, slugs or names)
$categories = array("clothing");
if( has_term( $categories, 'product_cat', $product->get_id() ) ){
$notify = true;
}
return $notify;
}
But it seems to be not working when I used the root product categories.
How can I get the root product categories in the if statements of the code?
Update 2 - 2018 Nov 17th (removed a bug and cleaned a bit)
To make it work for the parent categories, we add a custom conditional function that checks for parent product categories (where you will define your targeted parent product categories):
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Related: Allow backorders and notify customer for specific product categories in Woocommerce