Speed Up WooCommerce Square in WP-Admin

I was recently working on a WooCommerce store that had a very slow wp-admin. There were likely several factors involved, Query Monitor made it easy to see several API calls being made with every page load.

Query Monitor results with WooCommerce Square API call

If I could get rid of those API calls, then I could significantly increase the performance of wp-admin. With the WooCommerce Square plugin having the slowest API call, I started there.

After investigating, I found out that the API call was there to check if the server supported loopback connections. Since I knew my server did support loopback connections, I didn’t need this check. So, I just mocked out the API call, effectively removing it. Here’s the code that I used for that:

add_filter( 'pre_http_request', 'sport_shooting_depot_mock_square_background_check', 10, 3 );
function sport_shooting_depot_mock_square_background_check( $preemt, $args, $url ) {
	if ( $url !== 'YOUR_SITE_URL_HERE/wp-admin/admin-ajax.php?action=wc_square_background_sync_test' ) {
		return false;
	}

	return array(
		'body' => '[TEST_LOOPBACK]',
		'response' => array(
			'code' => '200 OK'
		),
	);
}

2 responses to “Speed Up WooCommerce Square in WP-Admin”

  1. I am having the same problem. Unfortunately the site is hosted at Godaddy. How did you add in that code?

    1. For adding the code, you’ve got a couple of options.

      The simplest option is probably to use a plugin like Code Snippets which provides a UI in wp-admin to add code snippets.

      The better option is probably to use SFTP or SSH and create a new mu-plugin file.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.