I trying to add the the product description to all my related products. This is the code I have from content-single-product.php template file:
<?php /** * Hook: woocommerce_after_single_product_summary. * * @hooked woocommerce_output_product_data_tabs - 10 * @hooked woocommerce_upsell_display - 15 * @hooked woocommerce_output_related_products - 20 */ do_action( 'woocommerce_after_single_product_summary' );
This is not working good for me because @hooked woocommerce_output_related_products - 20
has the image, title and price inside.
What I want is to have for each related product, the description under the product title.
Advertisement
Answer
The following will display only on related products section, the description under the product title (on single product pages):
add_action('woocommerce_shop_loop_item_title', 'description_after_related_product_title', 15 ); function description_after_related_product_title(){ global $woocommerce_loop, $product; // Only for related products: Display product description if( isset($woocommerce_loop['name']) && 'related' === $woocommerce_loop['name'] ) { echo '<p class="description">' . $product->get_description() . '</p>'; } }
Code goes in functions.php file of your active child theme (or active theme). Tested and works.