Beta: Stock Status?

Hi!

Another dynamic data that I haven’t found is the Stock status. We should be able to output custom In Stock and Out of Stock messages for the current product.

Sorry if this is available somewhere already. :slight_smile:

I have used to solve this with this code:

add_shortcode( 'stock_status', 'display_product_stock_status' );
function display_product_stock_status( $atts) {

    $atts = shortcode_atts(
        array('id'  => get_the_ID() ),
        $atts, 'stock_status'
    );

    $product = wc_get_product( $atts['id'] );

    $stock_status = $product->get_stock_status();

    if ( 'instock' == $stock_status) {
        return '<span class="stock in-stock">Available</span>';
    } else {
        return '<span class="stock out-of-stock">Not available</span>';
    }
}
1 Like

Let me reply to my topic instead of editing it. I understand that Conditions may be solving this, but I don’t have them in Beta 5 to test them. They should be appearing under the Customize tab of elements, but they are not there. I’m not sure why.

Gotcha, so under element conditions there’s a WC section with “Product (is)” and “Product (has)” options. If you choose “Product (is)” there are a bunch of options like is/is not “In Stock”, “On Sale”, “Downloadable” etc.

Strange that you don’t have those in beta 5. Might be that it’s trying to load an older version of the JS or that it didn’t truly update :confused: to the latest version.

1 Like

Hi Alex!

As commented earlier, I have downloaded Pro Beta 5 now, instead of upgrading via functions.php rule, and it now works as expected.

Thanks!

Awesome! Glad to hear it.