简体   繁体   English

在 WooCommerce 快速订单预览中显示自定义字段

[英]Show custom fields in WooCommerce quick order preview

In WooCommerce admin orders list, clicking on the "eye icon" gives a quick preview for the order info.在 WooCommerce 管理订单列表中,单击“眼睛图标”可以快速预览订单信息。

I've added custom billing checkout fields, but they are not shown in this quick preview and instead under billing details it displays "N/A":我添加了自定义帐单结帐字段,但它们未显示在此快速预览中,而是在帐单详细信息下显示“不适用”:

照片

However when choose the edit order page, I can see them.但是,在选择编辑订单页面时,我可以看到它们。

How to display that billing custom fields in order quick preview?如何显示计费自定义字段以便快速预览?

In the code below, for each of your billing custom fields, you will have to set the correct meta key .在下面的代码中,对于每个账单自定义字段,您必须设置正确的元键 It will display your billing custom fields in the quick order preview under Billing section:它将在账单部分下的快速订单预览中显示您的账单自定义字段:

add_filter( 'woocommerce_admin_order_preview_get_order_details', 'admin_order_preview_add_custom_billing_data', 10, 2 );
function admin_order_preview_add_custom_billing_data( $data, $order ) {
    $custom_billing_data = []; // initializing

    // Custom field 1: Replace '_custom_meta_key1' by the correct custom field metakey
    if( $custom_value1 = $order->get_meta('_custom_meta_key1') ) {
        $custom_billing_data[] = $custom_value1;
    }

    // Custom field 2: Replace '_custom_meta_key1' by the correct custom field metakey
    if( $custom_value2 = $order->get_meta('_custom_meta_key1') ) {
        $custom_billing_data[] = $custom_value2;
    }

    ## ……… And so on (for each additional custom field).

    // Check that our custom fields array is not empty
    if( count($custom_billing_data) > 0 ) {
        // Converting the array in a formatted string
        $formatted_custom_billing_data = implode( '<br>', $custom_billing_data );

        if( $data['formatted_billing_address'] === __( 'N/A', 'woocommerce' ) ) {
            $data['formatted_billing_address'] = $formatted_custom_billing_data;
        } else {
            $data['formatted_billing_address'] .= '<br>' . $formatted_custom_billing_data;
        }
    }

    return $data;
}

Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 It should work.它应该工作。

Related: Display custom data on Woocommerce admin order preview相关: 在 Woocommerce 管理订单预览中显示自定义数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 的订单编辑页面上显示自定义字段 - Show custom fields on the order editing page in WooCommerce 在订单页面的快速视图中显示woocommerce结帐中的自定义字段 - Show a custom field from the checkout of woocommerce on the quick view of the order page 在 WooCommerce 管理快速订单预览中自定义内容 - Customize content in WooCommerce admin quick order preview 在 WooCommerce 订单快速查看中显示使用过的优惠券 - Show used coupon in WooCommerce order quick view 在购物车和订单项目名称下显示 woocommerce 产品自定义字段 - Show woocommerce product custom fields under the cart and order item name 在 WooCommerce 快速订单预览 window 的新列中显示产品缩略图 - Display product thumbnail in new column in WooCommerce quick order preview window 在Woocommerce管理员订单预览上显示自定义数据 - Display custom data on Woocommerce admin order preview 高级自定义字段-woocommerce-显示字段 - Advanced custom fields - woocommerce - show fields 在Woocommerce 3中将产品自定义字段显示为订单商品 - Display product custom fields as order items in Woocommerce 3 订单自定义字段未显示在 WooCommerce email 通知上 - Order custom fields not displayed on WooCommerce email notifications
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM