Woocommerce Admin Order Details - Show user data on the order details page

I am looking for and trying it for 2 days without success, please help.

I want to filter orders for woocommerce in order to add additional data from db to the order details page based on the product attribute, but I cannot find a suitable action / filter hook for this task. Here, suppose I have the variable $is_customized = false ;

If $is_customized == true , then I need to add user data from the database to the order details page.

NOTE. I do not want to add an additional meta box, instead I want to change the details table for:

  • Replacing the default image with the image stored in the database and
  • Adding a div containing custom attributes under the product name.

I have all these values ​​in my variables, but I cannot figure out which one should be used.

I have added an image for clarification.

enter image description here

Just need to know if I can change / filter these order results and how?

I appreciate your time and help. Thanks

+5
source share
1 answer

Here's how to display some additional data in woocommerce_before_order_itemmeta :

 add_action( 'woocommerce_before_order_itemmeta', 'so_32457241)before_order_itemmeta', 10, 3 ); function so_32457241_before_order_itemmeta( $item_id, $item, $_product ){ echo '<p>bacon</p>'; } 

I do not know how you save your data, so I can not make a more accurate proposal. Keep in mind that immediately after this hook everything that you saved as the metadata of the order items will be automatically displayed.

Image filtering is more complicated. I found this gist at the beginning, but it requires some custom conditional logic, since you do not want thumbnail filtering everywhere, but only in orders.

Edit: Currently, the best I can do to filter element thumbnails is:

 add_filter( 'get_post_metadata', 'so_32457241_order_thumbnail', 10, 4 ); function so_32457241_order_thumbnail( $value, $post_id, $meta_key, $single ) { // We want to pass the actual _thumbnail_id into the filter, so requires recursion static $is_recursing = false; // Only filter if we're not recursing and if it is a post thumbnail ID if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) { $is_recursing = true; // prevent this conditional when get_post_thumbnail_id() is called $value = get_post_thumbnail_id( $post_id ); $is_recursing = false; $value = apply_filters( 'post_thumbnail_id', $value, $post_id ); // yay! if ( ! $single ) { $value = array( $value ); } } return $value; } add_filter( 'post_thumbnail_id', 'so_custom_order_item_thumbnail', 10, 2 ); function so_custom_order_item_thumbnail( $id, $post_id ){ if( is_admin() ){ $screen = get_current_screen(); if( $screen->base == 'post' && $screen->post_type == 'shop_order' ){ // this gets you the shop_order $post object global $post; // no really *good* way to check post item, but could possibly save // some kind of array in the order meta $id = 68; } } return $id; } 
+8
source

All Articles