• My website is set up on WordPress with Woocommerce. I’m trying to change the ‘out of stock’ message for a few specific products only. I found lots of information about changing the ‘out of stock’ message in this thread:

    https://www.ads-software.com/support/topic/plugin-woocommerce-excelling-ecommerce-changing-out-of-stock-to-coming-soon?replies=37

    One contributor, cokeyblokey, suggests that you can modify the theme function.php file to change the ‘out of stock’ message for a specific product:

    add_filter('woocommerce_get_availability', 'availability_filter_func');
    
    function availability_filter_func($availability)
    {
    if(is_single( array(2230,2232,2234,2236)))$availability['availability'] = str_ireplace('Out of stock', 'your text here', $availability['availability']);
    return $availability;
    }

    I’ve tried this but it doesn’t work for me. I’m fairly new to all this, so I might be wrong, but it seems from the WordPress codex that the first method above shouldn’t work, because of the following warning found at https://codex.www.ads-software.com/Conditional_Tags

    “Warning: You can only use conditional query tags after the posts_selection action hook in WordPress (the wp action hook is the first one through which you can use these conditionals). For themes, this means the conditional tag will never work properly if you are using it in the body of functions.php, i.e. outside of a function.”

    Is this why this isn’t working for me? Any ideas on how to do this successfully?

    By the way, I was able to change the ‘out of stock’ messages for the whole site using terrytsang’s suggestion from the same thread:

    //change woocommerce 'out of stock' product status to any text status you want
    add_filter('woocommerce_get_availability', 'custom_get_availability');
    
    function custom_get_availability($availability)
    {
    $availability['availability'] = str_ireplace('Out of stock', 'Coming Soon...', $availability['availability']);
    //$availability['availability'] = str_ireplace('Out of stock', 'Sold Out!', $availability['availability']);
    //$availability['availability'] = str_ireplace('Out of stock', 'Call for Price', $availability['availability']);
    
    return $availability;
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Woocommerce – Changing 'out of stock' message for specific products’ is closed to new replies.