I need to display product sales quantity on my orders backoffice.
Someone can give some help with this?
I can´t find any solution for this..
I already have this:
add_filter( 'manage_edit-shop_order_columns', 'admin_orders_list_add_column', 10, 1 );
function admin_orders_list_add_column( $columns ){
$columns['custom_column2'] = __( 'Quantidade', 'woocommerce' );
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'admin_orders_list_column_content', 10, 2 );
function admin_orders_list_column_content( $column, $post_id ){
global $post;
if ( 'custom_column2' === $column ) {
$order = wc_get_order( $post->ID );
echo '<p>Qty: ' . $order->get_items() . '</p>';
}
}
But is not working..
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Please try with this, I hope it will be help, I did try with this code. It’s work for me.
add_filter( 'manage_edit-shop_order_columns', 'admin_orders_list_add_column', 10, 1 );
function admin_orders_list_add_column( $columns ){
$columns['custom_column2'] = __( 'Quantidade', 'woocommerce' );
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'admin_orders_list_column_content', 10, 2 );
function admin_orders_list_column_content( $column){
global $the_order; // the global order object
if ( 'custom_column2' === $column ) {
// get items from the order global object
$order_items = $the_order->get_items();
if ( !is_wp_error( $order_items ) ) {
foreach( $order_items as $order_item) {
$order_count[$order_item["product_id"]] = $order_item["quantity"];
$total_order = array_sum($order_count);
}
echo '<p>Qty: ' . $total_order . '</p>';
}
}
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
