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

在“附加信息區域"上顯示單一和可變產品的

Display SKU on the #39;additional information area#39; for single and variable products(在“附加信息區域上顯示單一和可變產品的 SKU)
本文介紹了在“附加信息區域"上顯示單一和可變產品的 SKU的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試在單個產品附加信息選項卡的表格行中顯示產品的 SKU.

I'm trying to display the product's SKU inside the table row of single products Additional Information tab.

我嘗試使用 woocommerce_display_product_attributes 過濾器并顯示它(下面是我的代碼示例),但它僅適用于簡單產品.

I tried using the woocommerce_display_product_attributes filter and have it displayed (sample of my code below) but it only works with simple product.

When using variable products with different SKU, the field are not updated when (dropdown select) variation is selected and only show blank.有沒有合適的方法來做到這一點?

When using variable products with different SKU, the field are not updated when (dropdown select) variation is selected and only show blank. Is there a proper way to do this?

這是我當前的代碼:

// Displays SKU/Part# to Single product Additional information table rows
add_filter('woocommerce_display_product_attributes', 'wc_display_sku_additional_info_table', 10, 2);
function wc_display_sku_additional_info_table( $product_attributes, $product ){
    // Get product SKU
    $get_sku = ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' );

    $product_attributes[] = [
        'label' => __('SKU', 'woocommerce'),
        'value' => $get_sku,
    ];
    return $product_attributes;
}

推薦答案

這應該足夠了,注釋和解釋添加到我的代碼中

This should suffice, comment with explanation added to my code

  • 對于 singlevariable 產品,SKU 表行會添加到附加信息選項卡中.
  • SKU 表行根據variable 產品的下拉選擇菜單進行相應更新
  • For both single and variable products, a SKU table row is added to the additional information tab.
  • SKU table row is updated accordingly with the dropdown select menu for variable products
function display_product_attributes( $product_attributes, $product ) {
    // Simple product
    if ( $product->is_type('simple' ) ) {
        // Get product SKU
        $get_sku = ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' );

        // Add
        $product_attributes[ 'sku-field sku-field-single' ] = array(
            'label' => __('SKU', 'woocommerce'),
            'value' => $get_sku,
        );

    } 
    // Variable product
    elseif ( $product->is_type('variable' ) ) {
        // Get childIDs in an array
        $children_ids = $product->get_children();

        // Loop
        foreach ( $children_ids as $child_id ) {
            // Get product
            $product = wc_get_product( $child_id ); 

            // Get product SKU
            $get_sku = ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' );

            // Add
            $product_attributes[ 'sku-field sku-field-variable sku-field-variable-' . $child_id ] = array(
                'label' => __('SKU', 'woocommerce'),
                'value' => $get_sku,
            );
        }
        ?>
        <script>
        jQuery(document).ready(function($) {
            // Hide all rows
            $( '.sku-field-variable' ).css( 'display', 'none' );

            // Change
            $( 'input.variation_id' ).change( function() {
                // Hide all rows
                $( '.sku-field-variable' ).css( 'display', 'none' );

                if( $( 'input.variation_id' ).val() != '' ) {
                    var var_id = $( 'input.variation_id' ).val();

                    // Display current
                    $( '.sku-field-variable-' + var_id ).css( 'display', 'table-row' );
                }
            });    
        });
        </script>
        <?php
    }

    return $product_attributes;
}
add_filter('woocommerce_display_product_attributes', 'display_product_attributes', 10, 2);

這篇關于在“附加信息區域"上顯示單一和可變產品的 SKU的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 黄色毛片在线播放 | 亚洲一区二区三区高清 | 精品欧美一区二区三区久久久 | 亚洲成人av一区二区 | 亚洲精品中文在线观看 | 日韩视频在线播放 | 日韩视频在线观看中文字幕 | 精品成人免费视频 | 成人免费视频一区二区 | 日日摸日日添日日躁av | 欧美精产国品一二三区 | 久久久毛片 | 欧美亚洲综合久久 | av电影一区 | 男女羞羞视频大全 | 国产探花在线精品一区二区 | 91在线观看免费视频 | 日韩高清av | 国产精品毛片无码 | 色综合中文| 6080亚洲精品一区二区 | 国产精品久久国产精品99 gif | 亚洲欧洲一区 | 欧美日韩在线一区二区 | 国产精品视频网 | av在线三级 | a在线免费观看 | 91精品国产综合久久久久久 | 一区二区手机在线 | 国产高清精品一区二区三区 | 91麻豆精品国产91久久久久久久久 | 欧美成人一区二区三区 | 国产精品久久久久久久久免费相片 | 久久久久国产 | 综合网视频 | 天堂中文在线观看 | 91视频久久 | 91视频大全 | 国产精品久久精品 | 欧美日韩视频 | 国产在线精品一区 |