-1

I added some custom fields to the each product in Woocommerce, and I would like the data from the custom fields to show on the following receipt page (Order Details) after checkout is completed.

Just can't get it, not strong in php, why can't get anything. I've tried to use var_dump(get_post_custom($order->id)); i don't have my custom field in result.

Can somebody light me up?

Here is my code:

add_action( 'woocommerce_order_details_after_order_table', 'code_activation', 10, 1);

function code_activation($order){
    echo '<p><strong>'.__('Activation code').':</strong> ' . get_post_meta( $order->id, 'activation_code', true ). '</p>';

} 
Filburt
  • 17,626
  • 12
  • 64
  • 115

1 Answers1

0

You have added custom fields to the product. So custom fields will be associated with your product-id . But you are trying to retrieve the custom fields using $order->id which is wrong. following code should help to retrieve the product id from order. And using the product id you can retrieve your custom field.

    $orderItems = $order->get_items();
    foreach($orderItems as $orderItem)
    {
        $product_id   = $orderItem['variation_id'] ? $orderItem['variation_id'] : $orderItem['product_id'] );

    }
Filburt
  • 17,626
  • 12
  • 64
  • 115
DaZ
  • 1
  • 1
  • Thanks a lot, a think a got it, can you tell me please where i have to put this foreach – user3730710 Feb 16 '15 at 15:43
  • if you would like to display the details after product table and before the customer details then the hook u used is perfect woocommerce_order_details_after_order_table. Other hooks might be interesting to you are woocommerce_order_details_after_customer_details and woocommerce_order_items_table – DaZ Feb 17 '15 at 02:14
  • just did't get how to make it, did everything what you've told me, and get_post_meta( $order->id give me just word an "array", using var_dump shows that i'm still don't have my custom field, can you please give me little bit more explanation.I so sorry for be boring, seem I can't see hole picture, how it works, browsing thru web did't help me. – user3730710 Feb 18 '15 at 13:45