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
October 21, 2024 at 6:44 am
October 21, 2024 at 3:58 pm #16313428

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates and credentials. We will test it further and get back to you as soon as possible. Please wait.

--
Thanks!

Bigul

October 23, 2024 at 5:21 am #16319883

sagiS

Hello,

Is there is any update on this. Any Progress ? Please let us know where you are now?

October 23, 2024 at 8:57 am #16320800

Bigul
Supporter

Languages: English (English )

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

Hello,

I can reproduce the issue in a minimal setup on your staging site. So shared the details with our team for an expert opinion. We will get back to you as soon as possible. Please wait.

--
Thanks!

Bigul

October 24, 2024 at 4:50 pm #16327479

sagiS

Hello,
Any progress?

October 25, 2024 at 7:49 am #16329370

Bigul
Supporter

Languages: English (English )

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

Hello,

Our second-tier team is currently working on this ticket. We will get back to you as early as possible. Please wait.

--
Thanks!

Bigul

October 28, 2024 at 6:16 am #16335848

sagiS

Hello,

What's the update on this ticket?

October 28, 2024 at 4:43 pm #16339091

Bigul
Supporter

Languages: English (English )

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

Hello,

Sorry for the delay. Our second-tier team is still working on this bug, we will get back to you soon when we have an update from our team. Please wait. Thank you for your patience.

--
Thanks!

Bigul

October 30, 2024 at 4:40 pm #16348527

sagiS

Hello,

What sorry? Its been a month when this ticket was created and still you have not came to know whats the issue here. This is seriously not acceptable.

Also you wanted the staging and so I have created that for you and given all the access required to you.

I also have production website and we are facing this issue from last 5-6 months. I want this issue to be solved ASAP.

October 31, 2024 at 11:46 am #16351152

Bigul
Supporter

Languages: English (English )

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

Hello,

We understand your position and appreciate your patience. This was a challenging case for us, as our team struggled to debug it without a local copy of the site. However, we managed to replicate the issue on a fresh installation by creating over 1000 orders with a custom script.

Unfortunately, this behavior appears to be aligned with WooCommerce’s settings rather than an issue with WooCommerce Multilingual or WPML. For example, when there are many order items (like your USD orders), WooCommerce is configured to send an email. If there are fewer than two pages of orders, the CSV file will download directly. Once you have a minimum of 26 orders, the email option in WooCommerce becomes active.

Thank you for your kind understanding. Please feel free to ping us if you need any further assistance with WPML. We are happy to help always.

--
Thanks!

Bigul

October 31, 2024 at 12:53 pm #16351442

Bigul
Supporter

Languages: English (English )

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

Hello,

Maybe as a workaround, you can achieve it by adding a Download button to the Analytics report. Please try the following code after a full site backup and check whether it gives you the expected results or not. Refer to the attached images for more details.

function add_custom_export_button() {
	?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            // Check for WooCommerce's download button to confirm the page has loaded
            const interval = setInterval(function() {
                const downloadButton = $('.woocommerce-table__download-button');

                // If WooCommerce download button is found, add the custom export 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();
                        });

                    // Append the button after WooCommerce's default download button
                    downloadButton.after(customExportButton);

                    // Clear the interval to stop checking
                    clearInterval(interval);
                }
            }, 500); // Check every 500ms
        });
    </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,";
                    // Add CSV headers
                    const headers = ["Order ID", "Date", "Status", "Total"];
                    csvContent += headers.join(",") + "\r\n";

                    // Add data rows
                    data.orders.forEach(order => {
                        const row = [order.id, order.date, order.status, order.total];
                        csvContent += row.join(",") + "\r\n";
                    });

                    // Trigger CSV download
                    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() {
	// Check for user capability
	if (!current_user_can('manage_woocommerce')) {
		wp_send_json_error("Unauthorized", 403);
	}

	// Fetch WooCommerce orders
	$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');

--
Thanks!

Bigul

image.png
November 2, 2024 at 3:46 am #16356313

sagiS

Hello,

Okay I will try the code and update you.

November 4, 2024 at 8:36 am #16359243

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. Take your time. We will wait for your feedback.

--
Thanks!

Bigul

November 6, 2024 at 9:00 am #16370207
sagiS

Hello,

I have also reported second issue i.e "What steps can I take to address the speed issue at the admin side caused by background queries?". So your team has checked this issue or not?

We are facing admin side speed issue because of WPML background queries running. Please update me for this issue ASAP.

New threads created by Bigul and linked to this one are listed below:

https://wpml.org/forums/topic/background-queries-slowing-down-my-site-coming-up-on-each-refreshs/

November 6, 2024 at 2:19 pm #16372516

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. Please note that I have opened a new ticket for the *Performance related probems*, as per our support policies, we can only address one issue per ticket. This will help us serve you better and avoid discussing multiple problems in a single ticket. I will get back to you soon on the latest ticket. Please wait. Thank you for your understanding.

--
Thanks!

Bigul