• Resolved macfarmer

    (@macfarmer)


    Hey there,
    i added a column with total sales in the backend for products.
    The problem is, the code only sums up the sales for the orders in €, and doesnt include the sales for orders in $. How can i sum up all sales in all currencies?
    I use the plugin CurrencySwitcher and this is my snippet:

    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;
     
    }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add column in backend of products for sales count with multi currency’ is closed to new replies.