简体   繁体   中英

Show Custom Data in Woocommerce Order Details Admin Area

When a User Buys a Product he can generate up to 3 Serial Keys for his Product. This works fine so far. The User can see his Serials always in "my account" The Data gets stored in the Database: Table=Usermeta Meta=Product_Serial So from a Users Perspective evrything works fine but from the Admin Perspective not because the admin can´t see how much Serials the Customer has created and also he cant see the Serials the User is using.

Now I have created a Custom Field in the Theme functions.php with this code:

add_action( 'add_meta_boxes', 'add_meta_boxes' );
function add_meta_boxes()
{
    add_meta_box(
        'woocommerce-order-my-custom',
        __( 'Order Custom' ),
        'order_my_custom',
        'shop_order',
        'side',
        'default'
    );
}

But from here I don't know how to read out the Serial Key so the admin can see it. :( Any ideas ?

May be i am displaying data in wrong place in your order detail page. But you can check there is multipe hook avilable for this woocommerce/inculdes/admin/meta-boxes-/view/html-order-items.php .

I just take one this hook. Please add this code in functions.php

function my_function_meta_deta() {
    echo "I am here";
}
 add_action( 'woocommerce_admin_order_totals_after_refunded','my_function_meta_deta', $order->id );

在此输入图像描述

As coder said there is multiple hooks you can also try this out.

add_action('woocommerce_admin_order_data_after_order_details', 'my_custom_order_manipulation_function');
function my_custom_order_manipulation_function( $orderID ) {
    //dynamic functionalities / static html to display
}

Credits : Add order metadata to WooCommerce admin order overview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM