• Resolved hunio

    (@hunio)


    Hi there,

    Thanks before for creating a great plugin. I just found some issues with Woocommerce ‘sales report by product’ when I enabled Currency reports setting on General Options Page.

    With sales report by product, your filter override the default ‘where_meta’ query args. This is the original query args:

    Array
    (
        [data] => Array
            (
                [_line_total] => Array
                    (
                        [type] => order_item_meta
                        [order_item_type] => line_item
                        [function] => SUM
                        [name] => order_item_amount
                    )
    
            )
    
        [where_meta] => Array
            (
                [relation] => OR
                [0] => Array
                    (
                        [type] => order_item_meta
                        [meta_key] => Array
                            (
                                [0] => _product_id
                                [1] => _variation_id
                            )
    
                        [meta_value] => Array
                            (
                                [0] => 767
                            )
    
                        [operator] => IN
                    )
    
            )
    
        [query_type] => get_var
        [filter_range] => 1
        [order_status] => Array
            (
                [0] => completed
                [1] => processing
                [2] => on-hold
                [3] => refunded
            )
    
    )

    And this is when I enabled the setting:

    Array
    (
        [data] => Array
            (
                [_line_total] => Array
                    (
                        [type] => order_item_meta
                        [order_item_type] => line_item
                        [function] => SUM
                        [name] => order_item_amount
                    )
    
            )
    
        [where_meta] => Array
            (
                [0] => Array
                    (
                        [meta_key] => _order_currency
                        [meta_value] => AUD
                        [operator] => =
                    )
    
            )
    
        [query_type] => get_var
        [filter_range] => 1
        [order_status] => Array
            (
                [0] => completed
                [1] => processing
                [2] => on-hold
                [3] => refunded
            )
    
    )

    As you can see the ‘_product_id’ meta and ‘_variation_id’ is no longer exists and the report calculate all sales. I managed to fix by my self by hard coding the plugin file
    /plugins/currency-per-product-for-woocommerce/includes/class-alg-wc-cpp-currency-reports.php line 122 – 128 with this code:

    // check whether the 'where_meta' already used
    // if yes, append
    if ( $args['where_meta'] != ''){
    
    	$args['where_meta']['relation'] = 'AND';
    	$args['where_meta'][] = 
    			array(
    				'meta_key'   => '_order_currency',
    				'meta_value' => ( isset( $_GET['currency'] ) ? $_GET['currency'] : get_option( 'woocommerce_currency' ) ),
    				'operator'   => '=',
    			);
    
    // if no, create add new one
    } else {
    	$args['where_meta'] = array(
    			array(
    				'meta_key'   => '_order_currency',
    				'meta_value' => ( isset( $_GET['currency'] ) ? $_GET['currency'] : get_option( 'woocommerce_currency' ) ),
    				'operator'   => '=',
    			),
    	);
    
    }

    Can you please take consideration to add this change to your repository, I don’t like messing around with your plugin ??

    Or if you have any other suggestion, please let me know.

    Cheers

Viewing 1 replies (of 1 total)
  • Plugin Support kenil802

    (@kenil802)

    Hi @hunio,

    Thank you for appreciating our plugin.

    Regarding the query, I will ask the developer whether we can take this into consideration or not. Once I hear from the developer, I will get back to you with an update.

    Regards,
    Kenil Shah

Viewing 1 replies (of 1 total)
  • The topic ‘Sales by product report showing all sales’ is closed to new replies.