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

在 WooCommerce 3.0+ 中為簡短描述添加屬性

Add Attributes to Short Description in WooCommerce 3.0+(在 WooCommerce 3.0+ 中為簡短描述添加屬性)
本文介紹了在 WooCommerce 3.0+ 中為簡短描述添加屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我想將所有產(chǎn)品的屬性插入到它們的簡短描述中,以便客戶可以打開快速查看并檢查這些屬性.

我已經(jīng)嘗試過這個答案:顯示特定的產(chǎn)品屬性值在檔案類別頁面上

還有這個:Woocommerce - 顯示單個產(chǎn)品屬性(s) 在前端使用短代碼

我無法讓它發(fā)揮作用.我想應(yīng)該是因為 WooCommerce 更新到了 3.0+ 版

有人知道制作方法嗎?

謝謝

解決方案

Update 3(簡單產(chǎn)品的自動化,WC兼容性)

//WC 3+ 和自動化增強的兼容性add_action('woocommerce_shop_loop_item_title', 'custom_attributes_display', 20);函數(shù) custom_attributes_display(){全球$產(chǎn)品;//只針對簡單的產(chǎn)品if(!$product->is_type('simple')) 返回;$loop_count = 0;echo '

';//獲取屬性分類 slugs(現(xiàn)已更新和動態(tài))$attributes_taxonomy = $product->get_attributes();//或者設(shè)置一個分類slug(鍵)和名稱(值)的索引數(shù)組來選擇哪些,例如://$attributes_taxonomy = array('pa_nopeus' => 'Nopeus', 'pa_liito' => 'Liito, 'pa_vakaus' => 'Vaukaus' );foreach( $attributes_taxonomy as $taxonomy => $attribute ) {//獲取屬性的術(shù)語名稱(如果有多個值,則在逗號分隔的字符串中設(shè)置)$attribute_terms = wp_get_post_terms( get_the_id(), $taxonomy, array( 'fields' => 'names' ) );$terms_string = implode(',', $attribute_terms);//僅當(dāng)產(chǎn)品的屬性存在時才顯示if( count( $attribute_terms ) > 0 ){//更新回聲 $terms_string;//用|"分隔每個數(shù)字(現(xiàn)在更新和動態(tài))$attr_count = count( $attributes_taxonomy );$loop_count++;if( $loop_count < $attr_count && $attr_count > 1 ) echo ' |';}}回聲'</div>';}

<小時>

更新僅適用于 WooCommerce 3.0+ 版.

//適用于 WooCommerce 3.0+ 版(僅限)add_action('woocommerce_shop_loop_item_title', 'custom_attributes_display', 20);函數(shù) custom_attributes_display(){//僅用于產(chǎn)品類別檔案頁面如果(is_product_category()){全球$產(chǎn)品;//屬性名稱數(shù)組$attribute_names = array('pa_nopeus', 'pa_liito', 'pa_vakaus', 'pa_feidi');foreach( $attribute_names as $key => $attribute_name ) {//對于 WooCommerce 3.0+ 版$product_id = $product->get_id();//廁所 3.0+//獲取屬性的值(適用于 WC 3.0+)$wc_term = wc_get_product_terms( $product_id, $attribute_name);$attribute_value = array_shift($wc_term);//僅當(dāng)產(chǎn)品的屬性存在時才顯示if(!empty($attribute_value) || '0' == $attribute_value ){//更新回聲 $attribute_value;//用/"分隔每個數(shù)字if($key < 3) echo '/';}}}}

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

它現(xiàn)在應(yīng)該可以在 WC 3.0+ 中運行

<小時>

與此答案相關(guān)的代碼:Display檔案類別頁面上的特定產(chǎn)品屬性值

I would like to insert the attributes from all products to their short description, so the client can open a quickview and check this attributes.

I already tried this answer: Display specific product attribute values on archives category pages

Also this one: Woocommerce - Display single product attribute(s) with shortcodes in Frontend

And I wasn't able to make it work. I think it should be because WooCommerce got updated to version 3.0+

Does anyone know a way to make it?

Thanks

解決方案

Update 3 ( Automation for simple products, WC compatibility )

// Compatibility for WC 3+ and automation enhancements
add_action( 'woocommerce_shop_loop_item_title', 'custom_attributes_display', 20 );
function custom_attributes_display(){
    global $product;

    // Just for simple products
    if( ! $product->is_type( 'simple' ) ) return;

    $loop_count = 0;

    echo '<div>';

    // Get the attributes taxonomy slugs (Updated and dynamic now)
    $attributes_taxonomy = $product->get_attributes();
    // OR set an indexed array of taxonomy slug (key) and name (value) to chose which ones, like:
    // $attributes_taxonomy = array('pa_nopeus' => 'Nopeus', 'pa_liito' => 'Liito, 'pa_vakaus' => 'Vaukaus' );

    foreach( $attributes_taxonomy as $taxonomy => $attribute ) {

        // Getting the term names of an attribute (set in a coma separated string if many values)
        $attribute_terms = wp_get_post_terms( get_the_id(), $taxonomy, array( 'fields' => 'names' ) );
        $terms_string = implode( ',', $attribute_terms );

        // Displays only if attribute exist for the product
        if( count( $attribute_terms ) > 0 ){ // Updated
            echo $terms_string;

            // Separating each number by a " | " (Updated and dynamic now)
            $attr_count = count( $attributes_taxonomy );
            $loop_count++;
            if( $loop_count < $attr_count && $attr_count > 1 ) echo ' | ';
        }
    }

    echo '</div>';
}


Update For WooCommerce version 3.0+ only.

// For WooCommerce Version 3.0+ (only)
add_action( 'woocommerce_shop_loop_item_title', 'custom_attributes_display', 20 );
function custom_attributes_display(){

    // Just for product category archives pages
    if(is_product_category()){
        global $product;

        // the array of attributes names
        $attribute_names = array('pa_nopeus', 'pa_liito', 'pa_vakaus', 'pa_feidi');
        foreach( $attribute_names as $key => $attribute_name ) {

            // For WooCommerce version 3.0+
            $product_id = $product->get_id(); // WC 3.0+

            // Getting the value of an attribute (OK for WC 3.0+)
            $wc_term = wc_get_product_terms( $product_id, $attribute_name);
            $attribute_value = array_shift($wc_term);

            // Displays only if attribute exist for the product
            if(!empty($attribute_value) || '0' == $attribute_value ){ // Updated
                echo $attribute_value;

                // Separating each number by a " / "
                if($key < 3) echo ' / ';
            }
        }
    }
}

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

It should work now in WC 3.0+


Related to this Answer code: Display specific product attribute values on archives category pages

這篇關(guān)于在 WooCommerce 3.0+ 中為簡短描述添加屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
主站蜘蛛池模板: av在线免费看网址 | 亚洲麻豆 | 中文字幕久久精品 | 视频一区在线观看 | 国产欧美一区二区三区另类精品 | 久久久久国色av免费观看性色 | 天堂av中文 | 国产国产精品久久久久 | 日韩中字幕 | 99热播精品 | 亚洲 欧美 日韩 在线 | 国产一区二区三区www | 国产视频久久久 | 国产农村一级国产农村 | 黄视频在线网站 | 精品久久久久久久久久久久久久 | 亚洲成av人片在线观看 | 91免费在线 | 污片在线免费观看 | www在线视频| 精品三区 | 久久久久一区 | 色视频欧美 | 黑人巨大精品欧美一区二区免费 | 亚洲看片 | 久草免费在线视频 | 久久久久无码国产精品一区 | 中文字幕在线第一页 | 日本不卡一区二区三区在线观看 | 91一区二区三区在线观看 | 亚洲伊人久久综合 | 91麻豆精品国产91久久久久久久久 | 国产999精品久久久久久 | 国产成人叼嘿视频在线观看 | 国产精品a久久久久 | 91视视频在线观看入口直接观看 | 中文字幕一区二区三区四区五区 | 亚洲视频中文字幕 | 一区二区三区免费 | 成人一区二 | 成人精品在线观看 |