Add product total sales counter column to admin products list in WooCommerce

/**
 * Add new "Total Sales" column to products list
 */
add_filter( 'manage_edit-product_columns', 'add_product_column_total_sales', PHP_INT_MAX );
function add_product_column_total_sales( $columns ) {
	$columns['total_sales'] = 'Total Sales';
	return $columns;
}
/**
 * Output "Total Sales" column
 */
add_action( 'manage_product_posts_custom_column', 'render_product_column_total_sales', PHP_INT_MAX );
function render_product_column_total_sales( $column ) {
	if ( 'total_sales' != $column ) {
		return;
	}
	$total_sales = get_post_meta( get_the_ID(), 'total_sales', true );
	echo $total_sales;
}

No comments yet.

Leave a Reply