Search code examples
phpwordpresswoocommerceproductstock

Remove "can be backordered" from product page stock display in Woocommerce


It doesn't make sense to me to have the '(can be backordered)' text on a Woocommerce product page if the product is in stock as that confuses people because, after all, it's in stock!

I have found code to change the message if it is backordered but not how to remove it if the product is in stock and I have searched on the net for hours.

Can anyone provide me with the code required in the functions.php file or elsewhere to change it globally?


Solution

  • Updated

    The following code will remove "(can be backordered)" text from the product availability text, when product is in stock and backorders are allowed (with a customer notification):

    add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2 );
    function filter_product_availability_text( $availability, $product ) {
    
        if( $product->backorders_require_notification() ) {
            $availability = str_replace('(can be backordered)', '', $availability);
        }
        return $availability;
    }
    

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