Skip to content

Instantly share code, notes, and snippets.

@tivuno
Created October 31, 2024 17:25
Show Gist options
  • Save tivuno/20bc5d3cab7bca1cb2b863ce8ed158c6 to your computer and use it in GitHub Desktop.
Save tivuno/20bc5d3cab7bca1cb2b863ce8ed158c6 to your computer and use it in GitHub Desktop.
<?php
// Link example: https://mywebsite.com/wp-json (because we have woo, acf etc. that deploy their unique endpoints
function getWooCategories(string $link, string $consumer_key, string $consumer_secret)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $link . '/wc/v3/products/categories?per_page=100&consumer_key=' . $consumer_key . '&consumer_secret=' . $consumer_secret,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
]);
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment