I want to allow backorders for specific customer roles.
Code i writed is:
// BackOrder Allow Part #1
add_filter( 'woocommerce_product_backorders_allowed', 'woocommerce_product_backorders_allowed', 10, 3 );
function woocommerce_product_backorders_allowed( $backorder_allowed, $product_id, $product ){
if ( current_user_can('administrator') ) {
$backorder_allowed = true;
} else {
$backorder_allowed = false;
}
return $backorder_allowed;
}
// BackOrder Allow Part #2
add_filter( 'woocommerce_product_get_stock_status', 'woocommerce_product_get_stock_status', 10, 2 );
function woocommerce_product_get_stock_status( $stock_status, $product ) {
if ( current_user_can('administrator') ) {
return 'onbackorder';
}
else {
return 'outofstock';
}
}
Seems this gived result only for simple product.
How i can make work for other product types.
I need to work for simple, variable and yith-bundle.
Any help will be appreciated!
thanks!
2
Answers
I did change on second function. If it's outofstock, like qty = 0 or stockstatus be outofstock, to allow backorder
There are some mistakes and missing things in your code. Use the following instead:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.