问题
New products are being added daily to my website and it is unproductive to keep choosing the "Do not allow backorders" option for each new product and out of stock products. Currently with a growing database of over 2,000 products, I am finding it tedious to do the same process daily. Using the functions.php file, is there some php code I can implement to disallow backorders for all existing and future products?
Any help is welcome and appreciated.
回答1:
Simply use the following line of code to disable backorders globally:
add_filter( 'woocommerce_product_backorders_allowed', '__return_false' );
Code goes in functions.php file of your active child theme (or active theme). Tested and work.
In some cases, with some plugins you should define the priority hook, increasing it like:
add_filter( 'woocommerce_product_backorders_allowed', '__return_false', 1000 );
For backorder notifications there is the woocommerce_product_backorders_require_notification
filter.
来源:https://stackoverflow.com/questions/56291624/how-to-disable-globally-backorders-in-woocommerce