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

獲取 Woocommerce 檔案中當前產(chǎn)品類別的子類別

Get the subcategories of the current product category in Woocommerce archives(獲取 Woocommerce 檔案中當前產(chǎn)品類別的子類別)
本文介紹了獲取 Woocommerce 檔案中當前產(chǎn)品類別的子類別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試在 Woocommerce 中顯示當前類別下的子類別(不是子類別等),例如這個網(wǎng)站:http://www.qs-adhesivos.es/app/productos/productos.asp?idioma=en

I'm trying to Show subcategories (not subsubcategories,etc) under current category in Woocommerce like this Web: http://www.qs-adhesivos.es/app/productos/productos.asp?idioma=en

例如,Construction 是類別,Sealants &粘合劑、防水材料、聚氨酯泡沫……屬于子類別.

For Example, Construction is the category, and Sealants & adhesives, waterproofing, plyurethane foams… are subcategories.

密封劑膠粘劑是類別,而醋酸硅酮密封膠、中性硅酮密封膠、丙烯酸密封膠…是子類別…

Sealants & Mastics is the category, and ACETIC SILICONE SEALANT, NEUTRAL SILICONE SEALANT, ACRYLIC SEALANT… are subcategories…

在我的子主題下的 woocommerce 文件夾中已經(jīng)有一個 archive-product.php.

Already have an archive-product.php in a woocommerce folder under my child theme.

已經(jīng)嘗試了一些代碼并且它適用,但這不是我想要的.

Already tried some code and it applies but it's not what I want.

推薦答案

以下代碼將顯示產(chǎn)品類別存檔頁面的當前產(chǎn)品類別的格式化鏈接產(chǎn)品子類別:

The following code will display the formatted linked product subcategories from current product category for product category archive pages:

if ( is_product_category() ) {

    $term_id  = get_queried_object_id();
    $taxonomy = 'product_cat';

    // Get subcategories of the current category
    $terms    = get_terms([
        'taxonomy'    => $taxonomy,
        'hide_empty'  => true,
        'parent'      => get_queried_object_id()
    ]);

    $output = '<ul class="subcategories-list">';

    // Loop through product subcategories WP_Term Objects
    foreach ( $terms as $term ) {
        $term_link = get_term_link( $term, $taxonomy );

        $output .= '<li class="'. $term->slug .'"><a href="'. $term_link .'">'. $term->name .'</a></li>';
    }

    echo $output . '</ul>';
}

經(jīng)過測試并有效.

用法示例:

1) 您可以直接在 archive-product.php 模板文件中使用此代碼.

1) You can use this code directly in archive-product.php template file.

2) 您可以將代碼嵌入到函數(shù)中,替換最后一行 echo $output .'</ul>';return $output .'</ul>';,對于短代碼,總是返回顯示.

2) You can embed the code in a function, replacing the last line echo $output . '</ul>'; by return $output . '</ul>';, as for shortcodes, the display is always returned.

3) 您可以使用諸如 woocommerce_archive_description 之類的操作掛鉤來嵌入代碼:

3) You can embed the code using action hooks like woocommerce_archive_description:

// Displaying the subcategories after category title
add_action('woocommerce_archive_description', 'display_subcategories_list', 5 ); 
function display_subcategories_list() {
    if ( is_product_category() ) {

        $term_id  = get_queried_object_id();
        $taxonomy = 'product_cat';

        // Get subcategories of the current category
        $terms    = get_terms([
            'taxonomy'    => $taxonomy,
            'hide_empty'  => true,
            'parent'      => $term_id
        ]);

        echo '<ul class="subcategories-list">';

        // Loop through product subcategories WP_Term Objects
        foreach ( $terms as $term ) {
            $term_link = get_term_link( $term, $taxonomy );

            echo '<li class="'. $term->slug .'"><a href="'. $term_link .'">'. $term->name .'</a></li>';
        }

        echo '</ul>';
    }
}

代碼位于活動子主題(或活動主題)的 functions.php 文件中.經(jīng)測試有效.

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

要在類別描述后顯示,請將鉤子優(yōu)先級從 5 更改為 20 在:

To display it after the category description, change the hook priority from 5 to 20 in:

add_action('woocommerce_archive_description', 'display_subcategories_list', 5 ); 

喜歡:

add_action('woocommerce_archive_description', 'display_subcategories_list', 20 ); 

這篇關(guān)于獲取 Woocommerce 檔案中當前產(chǎn)品類別的子類別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
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 簡單產(chǎn)品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 伊人精品视频 | 国精产品一区一区三区免费完 | 日韩在线免费看 | 亚洲综合小视频 | 久久久久久国产 | 欧美久久一区二区 | 日本欧美在线视频 | 国产日韩一区二区三免费高清 | 欧美毛片免费观看 | 欧美色综合一区二区三区 | www.性色| 精品国产三级 | 国内精品久久影院 | 国产福利在线小视频 | 亚洲国产成人精品久久久国产成人一区 | 久久区二区 | 欧美国产日韩成人 | 日韩精品一区二区三区在线观看 | 久久久99国产精品免费 | 久久久久国产 | 久久久国产一区二区三区 | av性色全交蜜桃成熟时 | 欧美日韩一区二区三区四区 | 久久久久久久一区 | 在线观看免费毛片 | av一级久久 | 亚洲精品在线观看视频 | 午夜久久久 | www.99精品| 成人av电影免费在线观看 | 四虎午夜剧场 | 精品国产乱码久久久久久88av | 精品国产18久久久久久二百 | 91欧美精品成人综合在线观看 | 三级视频在线观看 | 日日干干 | 国产精品国产成人国产三级 | 女人夜夜春| 国产精品揄拍一区二区 | 国产999精品久久久久久 | 一区二区三区四区国产 |