Hi, @s10dulkar!
Yes, the following code should add a “Total sales” column to the products:
add_filter( 'manage_edit-product_columns', 'misha_total_sales_1', 20 );
add_action( 'manage_posts_custom_column', 'misha_total_sales_2' );
add_filter('manage_edit-product_sortable_columns', 'misha_total_sales_3');
add_action( 'pre_get_posts', 'misha_total_sales_4' );
function misha_total_sales_1( $col_th ) {
return wp_parse_args( array( 'total_sales' => 'Total Sales' ), $col_th );
}
function misha_total_sales_2( $column_id ) {
if( $column_id == 'total_sales' )
echo get_post_meta( get_the_ID(), 'total_sales', true );
}
function misha_total_sales_3( $a ){
return wp_parse_args( array( 'total_sales' => 'by_total_sales' ), $a );
}
function misha_total_sales_4( $query ) {
if( !is_admin() || empty( $_GET['orderby']) || empty( $_GET['order'] ) )
return;
if( $_GET['orderby'] == 'by_total_sales' ) {
$query->set('meta_key', 'total_sales' );
$query->set('orderby', 'meta_value_num');
$query->set('order', $_GET['order'] );
}
return $query;
}
Also see: https://rynaldostoltz.com/how-to-add-custom-code-to-your-woocommerce-wordpress-site-the-right-way/
Cheers!