Skip to content

Instantly share code, notes, and snippets.

@runezero
Created July 26, 2022 13:29
Show Gist options
  • Save runezero/750b18be41db70d420b0f167ea78372b to your computer and use it in GitHub Desktop.
Save runezero/750b18be41db70d420b0f167ea78372b to your computer and use it in GitHub Desktop.
[Display products in order table] Shows the purchased products in the admin order table #woocommerce
add_filter( 'manage_edit-shop_order_columns', 'dev_show_product_order',15 );
function dev_show_product_order($columns){
//add column
$columns['product-display'] = __( 'Products');
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'dev_custom_shop_order_column', 10, 2 );
function dev_custom_shop_order_column( $column ) {
global $post, $woocommerce, $the_order;
switch ( $column ) {
case 'product-display' :
$terms = $the_order->get_items();
if ( is_array( $terms ) && !empty( $terms ) {
foreach($terms as $term)
{
echo $term['item_meta']['_qty'][0] .' x ' . $term['name'];
}
} else {
_e( 'Unable get the products', 'woocommerce' );
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment