Site logo

[Support request] Add stock status to product archives and categories

Home Forums Support [Support request] Add stock status to product archives and categories

Home Forums Support Add stock status to product archives and categories

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2506460
    Jesse

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

    #2506484
    Ying
    Staff
    Customer Support

    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.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.