So, like the title says, I am looking for a way to override the setting that makes a products that is out of stock not purchasable. I know I am supposed to use the "allow on backorder" setting to do this, but we have a big issue with this:

We need our product filter to be able to handle sorting on stock status based on the variations, and so far all the filters I have testet that is supposed to handle this will not work on stock status if it is on allow on backorder. There seems to be an issue with the amount of variations we have per product(80-200 variations per product), because if I create a test product with 2-10 variations, the filters I have tested seem to work just fine. And for some weird reason, the filter seems to work just fine if the variations use not in stock status instead of allow on backorder staus.

So, as a workaround, I am really hoping someone can help me to figure out how to allow purchase of out of stock products in the functions file :)


The following hooked functions will allow you to make everything purchasable:

// Change all products stock statuses to 'instock'
add_filter( 'woocommerce_product_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
add_filter( 'woocommerce_product_variation_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
function filter_get_stock_status_callback( $stock_status, $product ){
    return is_admin() ? $stock_status : 'instock';

// Enable backorders on all products
add_filter( 'woocommerce_product_get_backorders', 'filter_get_backorders_callback', 10, 2 );
add_filter( 'woocommerce_product_variation_get_backorders', 'filter_get_backorders_callback', 10, 2 );
function filter_get_backorders_callback( $backorders_status, $product ){
    return 'yes'; // Enable without notifications

// Remove the stock quantity from displayed stock status
add_filter( 'woocommerce_get_availability_text', 'filter_get_availability_text_callback', 10, 2 );
function filter_get_availability_text_callback( $availability_text, $product ){
    return __( 'In stock', 'woocommerce');

Code goes in function.php file of the active child theme (or active theme). Tested and works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.