Search code examples
phpwordpresswoocommerceadminorders

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 ?


Solution

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

    enter image description here