Created
July 26, 2022 13:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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