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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 WooCommerce 的訂單編輯頁(yè)面上顯示自定義字段

在 WooCommerce 的訂單編輯頁(yè)面上顯示自定義字段

PHP
慕哥6287543 2021-06-29 17:59:41
基于“在購(gòu)物車(chē)和訂單項(xiàng)目名稱下顯示 woocommerce 產(chǎn)品自定義字段”對(duì)我之前的一個(gè)問(wèn)題的回答,代碼在產(chǎn)品編輯頁(yè)面上顯示自定義字段。填寫(xiě)這些字段后,產(chǎn)品頁(yè)面上會(huì)顯示數(shù)據(jù)。這是代碼:// Backend: Display additional product fieldsadd_action('woocommerce_product_options_general_product_data', 'add_fields_to_options_general_product_data');function add_fields_to_options_general_product_data() {    // Custom Weight Field    woocommerce_wp_text_input(array(            'id' => '_custom_weight',            'label' => __('Weight dishes', 'woocommerce'),    ));    // Calories Field    woocommerce_wp_text_input(array(            'id' => '_сalories',            'label' => __('Calories', 'woocommerce'),    ));    // Ingredients Field    woocommerce_wp_textarea_input(array(            'id' => '_ingredients',            'label' => __('Ingredients', 'woocommerce'),    ));}// Backend: Save the data value from the custom fieldsadd_action('woocommerce_admin_process_product_object', 'save_admin_product_custom_fields_values');function save_admin_product_custom_fields_values($product) {    // Save Custom Weight Field    if (isset($_POST['_custom_weight'])) {            $product->update_meta_data('_custom_weight', sanitize_text_field($_POST['_custom_weight']));    }    // Save Calories Field    if (isset($_POST['_сalories'])) {            $product->update_meta_data('_сalories', sanitize_text_field($_POST['_сalories']));    }    // Save Ingredients Field    if (isset($_POST['_ingredients'])) {            $product->update_meta_data('_ingredients', sanitize_textarea_field($_POST['_ingredients']));    }}如何在管理面板的編輯訂單頁(yè)面上顯示自定義字段?它應(yīng)該在產(chǎn)品名稱之后顯示這些字段。
查看完整描述

1 回答

?
慕尼黑的夜晚無(wú)繁華

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊

以下是在管理訂單項(xiàng)目上顯示您的產(chǎn)品自定義字段的方法:


add_action( 'woocommerce_before_order_itemmeta', 'add_admin_order_item_custom_fields', 10, 2 );

function add_admin_order_item_custom_fields( $item_id, $item ) {

    // Targeting line items type only

    if( $item->get_type() !== 'line_item' ) return;


    $product = $item-> get_product();

    $value1  = $product->get_meta('_custom_weight');

    $value2  = $product->get_meta('_сalories');

    $value3  = $product->get_meta('_ingredients');


    if ( ! empty($value1) || ! empty($value2) || ! empty($value3) ) {

        echo '<table cellspacing="0" class="display_meta">';


        if ( ! empty($value1) ) {

            echo '<tr><th>' . __("Weight", "woocommerce") . ':</th><td>' . $value1 . 'g</td></tr>';

        }


        if ( ! empty($value2) ) {

            echo '<tr><th>' . __("Calories", "woocommerce") . ':</th><td>' . $value2 . 'kcal</td></tr>';

        }


        if ( ! empty($value3) ) {

            echo '<tr><th>' . __("Ingredients", "woocommerce") . ':</th><td>' . $value3 . '</td></tr>';

        }

        echo '</table>';

    }

}

代碼位于活動(dòng)子主題(或活動(dòng)主題)的 functions.php 文件中。測(cè)試和工作。

http://img1.sycdn.imooc.com//60dec88e00012eeb07740202.jpg

查看完整回答
反對(duì) 回復(fù) 2021-07-02
  • 1 回答
  • 0 關(guān)注
  • 355 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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