久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 WooCommerce 存檔頁面的產品標題下添加簡短的描

Add shortened description under the product title in WooCommerce archive pages(在 WooCommerce 存檔頁面的產品標題下添加簡短的描述)
本文介紹了在 WooCommerce 存檔頁面的產品標題下添加簡短的描述的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在 Woocommerce 檔案頁面中,我應該需要在每個產品標題下顯示產品描述中的幾行,如本圖所示.

In Woocommerce archives pages, I should need to display couple of lines from the product description under each product title like it's shown in this image.

我該怎么做?

推薦答案

更新: 此自定義功能將縮短產品描述(到定義的字數)并將其顯示在存檔頁面中的每個產品作為商店:

Updated: This custom function will shorten the product description (to a defined amount of words) and will display it under the title of each product in archive pages as shop:

add_action('woocommerce_after_shop_loop_item_title', 'description_in_shop_loop_item', 3 );
function description_in_shop_loop_item() {
    global $product;

    // HERE define the number of words
    $limit = 10;

    $description = $product->get_description(); // Product description
    // or
    // $description = $product->get_short_description(); // Product short description

    // Limit the words length
    if (str_word_count($description, 0) > $limit) {
        $words = str_word_count($description, 2);
        $pos = array_keys($words);
        $excerpt = substr($description, 0, $pos[$limit]) . '...';
    } else {
        $excerpt = $description;
    }

    echo '<p class="description">'.$excerpt.'</p>';
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.

Code goes in function.php file of your active child theme (or active theme).

或者您可以根據字符長度限制使用相同的內容:

Or you can have the same thing based on characters length limit:

add_action('woocommerce_after_shop_loop_item_title', 'description_in_shop_loop_item', 3 );
function description_in_shop_loop_item() {
    global $product;

    // HERE define the number of characters
    $limit = 75;

    $description = $product->get_description(); // Product description
    // or
    // $description = $product->get_short_description();  // Product short description

    // Limit the characters length
    if (strlen($description) > $limit) {
        $excerpt = substr($description, 0, $limit) . '...';
    } else {
        $excerpt = $description;
    }

    echo '<p class="description">'.$excerpt.'</p>';
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.

Code goes in function.php file of your active child theme (or active theme).

這兩個功能都經過測試和工作.

Both functions are tested and works.

這篇關于在 WooCommerce 存檔頁面的產品標題下添加簡短的描述的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 99久久久国产精品免费消防器 | 欧美影院 | 久久亚洲国产精品日日av夜夜 | 成人午夜免费在线视频 | 欧美视频免费在线 | 欧美日韩亚洲成人 | 亚洲国产精品久久 | 久久久区 | 国产男人的天堂 | 91精品国产综合久久婷婷香蕉 | 夜夜爽99久久国产综合精品女不卡 | 先锋资源网 | 欧美精品在欧美一区二区 | 美女一级a毛片免费观看97 | 三级在线观看 | 一区二区在线 | 国产丝袜一区二区三区免费视频 | 色播视频在线观看 | 久久中文字幕一区 | 精品综合久久久 | 日韩视频a| 国产福利一区二区 | 中文字幕高清免费日韩视频在线 | 欧美片网站免费 | 日本精品在线播放 | 成人国产精品久久 | 日韩精品欧美精品 | 一区精品国产欧美在线 | 午夜影视 | 精品免费国产视频 | 日韩中文在线观看 | 午夜国产| 中文字幕在线不卡播放 | 欧美一区二区三区在线播放 | www.四虎.com| 国产高清久久 | 国产成人91| 日韩在线不卡 | 激情小说综合网 | 亚洲精品一区中文字幕 | 欧美在线观看一区二区 |