我嘗試將產品描述添加到我的所有相關產品中。 這是我從 content-single-product.php 模板文件中獲得的代碼:<?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' );這對我來說效果不好,因為@hooked woocommerce_output_related_products - 20里面有圖像、標題和價格。我想要的是每個相關產品的產品標題下的描述。
1 回答

qq_花開花謝_0
TA貢獻1835條經驗 獲得超7個贊
以下內容僅顯示在相關產品部分,產品標題下的描述(在單個產品頁面上):
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>';
}
}
代碼位于活動子主題(或活動主題)的functions.php 文件中。經過測試并有效。
- 1 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消