Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing two issues: 1. WooCommerce analytics reports are not downloading for currencies like USD and Euro, instead, they are being sent via email. 2. There is a speed issue on the admin side due to background queries.
Solution:
For the first issue, it was determined that this behavior aligns with WooCommerce's settings. When there are many order items, WooCommerce is configured to send an email instead of downloading the CSV file directly. This is not an issue with WooCommerce Multilingual or WPML.
For the second issue, we provided a custom code solution to add a 'Direct Export (Browser)' button to the Analytics report page. This button allows for direct downloading of the report without waiting for an email. Here is the code to implement:

function add_custom_export_button() { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            const interval = setInterval(function() {
                const downloadButton = $('.woocommerce-table__download-button');
                if (downloadButton.length) {
                    const customExportButton = $('<button class="button-primary" style="margin-left: 10px;">Direct Export (Browser)</button>')
                        .on("click", function(e) {
                            e.preventDefault();
                            fetchAndDownloadCSV();
                        });
                    downloadButton.after(customExportButton);
                    clearInterval(interval);
                }
            }, 500);
        });
    </script>
<?php }
add_action('admin_footer', 'add_custom_export_button');
function custom_export_script() { ?>
    <script type="text/javascript">
        async function fetchAndDownloadCSV() {
            try {
                const response = await fetch('<?php echo admin_url('admin-ajax.php?action=custom_order_export'); ?>');
                const data = await response.json();
                if (data && data.orders) {
                    let csvContent = "data:text/csv;charset=utf-8,";
                    const headers = ["Order ID", "Date", "Status", "Total"];
                    csvContent += headers.join(",") + "\r\n";
                    data.orders.forEach(order => {
                        const row = [order.id, order.date, order.status, order.total];
                        csvContent += row.join(",") + "\r\n";
                    });
                    const encodedUri = encodeURI(csvContent);
                    const link = document.createElement("a");
                    link.setAttribute("href", encodedUri);
                    link.setAttribute("download", "orders_export.csv");
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                } else {
                    alert("No order data found.");
                }
            } catch (error) {
                console.error("Export failed:", error);
                alert("There was an error fetching the order data.");
            }
        }
    </script>
<?php }
add_action('admin_footer', 'custom_export_script');
function custom_order_export() {
    if (!current_user_can('manage_woocommerce')) {
        wp_send_json_error("Unauthorized", 403);
    }
    $orders = wc_get_orders(array(
        'limit' => -1,
        'orderby' => 'date',
        'order' => 'DESC',
        'return' => 'ids',
    ));
    $order_data = array();
    foreach ($orders as $order_id) {
        $order = wc_get_order($order_id);
        $order_data[] = array(
            'id' => $order->get_id(),
            'date' => $order->get_date_created()->date('Y-m-d H:i:s'),
            'status' => $order->get_status(),
            'total' => $order->get_total(),
        );
    }
    wp_send_json(array('orders' => $order_data));
}
add_action('wp_ajax_custom_order_export', 'custom_order_export');

https://wpml.org/forums/topic/woocommerce-analytics-report-not-downloading-for-other-currency-speed-issue-at-admin-side-2/page/2/#post-16351152

https://wpml.org/forums/topic/woocommerce-analytics-report-not-downloading-for-other-currency-speed-issue-at-admin-side-2/page/2/#post-16351442

If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your specific case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please feel free to open a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 22 replies, has 0 voices.

Last updated by Bigul 1 week, 1 day ago.

Assisted by: Bigul.

Author Posts
November 6, 2024 at 4:55 pm #16374110

sagiS

Hello,

Please do not close this thread as still I have not tested your code on our production.

Thanks

November 7, 2024 at 5:25 am #16375202

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for the updates. Take your time. The ticket will not be closed for two weeks. We will wait for your feedback.

--
Thanks!

Bigul

November 14, 2024 at 10:35 am #16401695

sagiS

Hello,

There are few points to discuss on this thread are as follows:

1. for the code you provided is downloading all orders from single ajax request which I think creates a load on server as we have 50k-60k orders so this code needs to be modified.

2. Can you provide the code which can work with above filters like date and currency? So that we can download monthly report or based on currency.

3. for Euro currency, why we are not receiving email. Also it is not showing inside Mail Log.

Please give the answers of above questions ASAP.

Thanks

November 14, 2024 at 4:44 pm #16404266

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for the updates. Please note that as per our support policies we have limitations for the custom code support. Thank you for your kind understanding. I have shared it with our team. We will get back to you soon.

WooCommerce is configured to send an email when we have many orders. If there are fewer than two pages of orders, the CSV file will download directly. Once we have a minimum of 26 orders, the email option in WooCommerce becomes active. So please check how many euro orders you have now.

--
Thanks!

Bigul

November 15, 2024 at 11:22 am #16407756

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

After carefully reviewing your request, it appears to be a custom coding requirement, which falls outside the scope of the support we offer. Upon investigation, we have identified that this behavior is a built-in feature of WooCommerce, designed to manage server load effectively. Therefore we would kindly recommend you to reaching out to the WooCommerce team for further assistance. They should be able to guide you better in this case.

We truly appreciate your understanding. Please feel free to ping us if you need any further assistance with WPML.

--
Thanks!

Bigul