2
votes

I've added WooCommerce featured product to my homepage using a shortcode.

I would like also show the product description as well.

With the code below, the featured product are displayed with the thumbnail, title, price and add to cart button:

<section id="solutions-wrap">
<div class="container">
  <?php echo do_shortcode('[featured_products]'); ?>
</div>

After some research, I can't seem to find anything that helps. Should I use the shortcode or a loop?

1

1 Answers

1
votes

Since WooCommerce 3.2, WooCommerce shortcode [featured_products] is now replaced by:

[products visibility="featured"]

The following will add the product description to featured products shortcode:

add_action( 'woocommerce_shop_loop_item_title', 'add_product_description_products_shortcode', 20 );
function add_product_description_products_shortcode() {
    global $product, $woocommerce_loop;
    
    if( isset($woocommerce_loop['is_shortcode']) && $woocommerce_loop['is_shortcode'] == '1'
    &&  isset($woocommerce_loop['name']) && $woocommerce_loop['name'] === 'products' 
    && $product->is_featured() ) {
        echo '<p class="product-description">' . $product->get_description() . '</p>';
    }
}

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