第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在單一和可變產(chǎn)品的“附加信息區(qū)域”顯示 SKU

在單一和可變產(chǎn)品的“附加信息區(qū)域”顯示 SKU

PHP
牛魔王的故事 2023-04-28 14:27:20
我試圖在單個產(chǎn)品附加信息選項(xiàng)卡的表行中顯示產(chǎn)品的 SKU。我嘗試使用woocommerce_display_product_attributes過濾器并顯示它(下面是我的代碼示例),但它只適用于簡單的產(chǎn)品。當(dāng)使用具有不同 SKU 的可變產(chǎn)品時,選擇(下拉選擇)變體時該字段不會更新,只會顯示空白。有沒有正確的方法來做到這一點(diǎn)?這是我當(dāng)前的代碼:// Displays SKU/Part# to Single product Additional information table rowsadd_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;}
查看完整描述

1 回答

?
寶慕林4294392

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個贊

這應(yīng)該足夠了,注釋并添加到我的代碼中

  • 對于 和single產(chǎn)品variable,SKU 表行添加到附加信息選項(xiàng)卡。

  • SKU 表格行會根據(jù)variable產(chǎn)品的下拉選擇菜單進(jìn)行相應(yīng)更新

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);



查看完整回答
反對 回復(fù) 2023-04-28
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號