This standalone script connects to Square Locations API via cURL and returns existing locations on your account. This is helpful when the WooCommerce Square extension does not retrieve the locations, and web hosts claim that cURL is working as expected
<?php
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://connect.squareup.com/v2/locations' );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer PRODUCTION_ACCESS_TOKEN', 'Accept: application/json', 'Square-Version: 2021-04-21' ) );
curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
if ( curl_exec( $ch ) === false ) {
echo 'Curl error: ' . curl_error( $ch );
} else {
$data = json_decode( curl_exec( $ch ) );
echo '<pre>';
print_r( $data );
echo '</pre>';
}
curl_close( $ch );
This is not a WordPress plugin, so please upload this script to the root directory of the site and access it directly: https://example.com/square-list-locations.php
For Production environment:
PRODUCTION_ACCESS_TOKEN with the ACCESS token from your app at https://developer.squareup.com/apps/For Sandbox environment:
https://connect.squareup.com/v2/locations with https://connect.squareupsandbox.com/v2/locations PRODUCTION_ACCESS_TOKEN in the script, with the Sandbox Access token insteadIf things work fine, you’ll see a list of Square locations and their details. If not, you’ll see the cURL error.
All cURL errors start with Curl error:. If you don’t see that, it means the error you’re seeing is returned by Square.
Source/Credits: https://developer.squareup.com/docs/locations-api