Site logo

Archived topic

Add stock status to product archives and categories

1 reply · Started by Jesse on January 23, 2023

Viewing posts 1–2 of 2

Is there an easy way to add stock status ("in stock" or "out of stock") to the woocommerce product archive and category pages?

Hi Jesse,

Give this PHP code a try:

add_action( 'woocommerce_after_shop_loop_item', 'get_product_stock_availability', 10 ); 

function get_product_stock_availability() {
    global $wpdb, $product;

    // For variable products
    if( $product->is_type('variable') ) {
    }
    // Other products types
    else {
        echo wc_get_stock_html( $product );
    }
}

to position it to a different location, please check the visual guide of Woo hooks:
https://www.businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/

For example, if you think woocommerce_shop_loop_item_title is a better location, then replace woocommerce_after_shop_loop_item with woocommerce_shop_loop_item_title in the code.

This archived topic is closed to new replies.