久久久久久久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)
主站蜘蛛池模板: 国产一级电影在线 | 久久精点视频 | 国产精品久久久久久久7电影 | 欧美精品二区 | 久久欧美精品 | 精品欧美一区免费观看α√ | 久久久久久久久国产精品 | 91精品午夜窝窝看片 | 久久国产精品久久久久久 | 午夜日韩 | 韩日一区二区三区 | 成人在线 | 黄毛片| 久久国产精品久久久久久 | 六月色婷 | 久久久999免费视频 999久久久久久久久6666 | 欧美精品一区二区三区一线天视频 | 国产在线成人 | 97久久精品| 超碰导航 | 久久久久久蜜桃一区二区 | 欧美亚洲国产一区 | 国产精品亚洲一区二区三区在线 | 日韩视频在线播放 | 亚洲一区二区三区视频 | 精品自拍视频 | 亚洲成人国产 | 尤物在线精品视频 | 人人干人人艹 | 在线免费观看黄视频 | 国产一区二区精品在线观看 | 国产99久久久国产精品下药 | 夜夜av | 久久成人18免费网站 | 日韩在线精品强乱中文字幕 | 日韩免费视频一区二区 | 在线国产一区二区 | 欧美日韩国产一区二区三区 | 鲁一鲁资源影视 | 欧美日韩综合 | 狠狠插狠狠操 |