PHP
PHP
WooCommerce List Products having SKU
See more WooCommerce Examples
Gets information for a product by SKU.Chilkat PHP Downloads
<?php
use Chilkat2\Http;
use Chilkat2\JsonArray;
use Chilkat2\StringBuilder;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new Http();
// Implements the following CURL command:
// curl https://example.com/wp-json/wc/v3/products?sku=3386460107914 \
// -u consumer_key:consumer_secret
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
$http->BasicAuth = true;
$http->Login = 'consumer_key';
$http->Password = 'consumer_secret';
$sbResponseBody = new StringBuilder();
$http->SetUrlVar('sku', '3386460107914');
// Use "https" or "http" depending on what your site needs.
try {
$http->QuickGetSb('http://example.com/wp-json/wc/v3/products?sku={$sku}', $sbResponseBody);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$jarrResp = new JsonArray();
$jarrResp->LoadSb($sbResponseBody);
$jarrResp->EmitCompact = false;
echo "Response Body:\n";
echo $jarrResp->Emit(), "\n";
$respStatusCode = $http->LastStatus;
echo 'Response Status Code = ', $respStatusCode, "\n";
if ($respStatusCode >= 400) {
echo "Response Header:\n";
echo $http->LastHeader, "\n";
echo "Failed.\n";
exit;
}