Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PHP ActiveX) WooCommerce Update a ProductSee more WooCommerce ExamplesDemonstrates how to make changes to a product in WooCommerce. For more information, see https://woocommerce.github.io/woocommerce-rest-api-docs/#update-a-product
<?php // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.Http') $http = new COM("Chilkat.Http"); // Implements the following CURL command: // curl -X PUT https://example.com/wp-json/wc/v3/products/794 \ // -u consumer_key:consumer_secret \ // -H "Content-Type: application/json" \ // -d '{ // "regular_price": "24.54" // }' // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code $http->BasicAuth = 1; $http->Login = 'consumer_key'; $http->Password = 'consumer_secret'; // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "regular_price": "24.54" // } // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.JsonObject') $json = new COM("Chilkat.JsonObject"); $json->UpdateString('regular_price','24.54'); $http->SetRequestHeader('Content-Type','application/json'); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.StringBuilder') $sbRequestBody = new COM("Chilkat.StringBuilder"); $json->EmitSb($sbRequestBody); // resp is a Chilkat.HttpResponse $resp = $http->PTextSb('PUT','https://example.com/wp-json/wc/v3/products/794',$sbRequestBody,'utf-8','application/json',0,0); if ($http->LastMethodSuccess == 0) { print $http->LastErrorText . "\n"; exit; } // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.StringBuilder') $sbResponseBody = new COM("Chilkat.StringBuilder"); $resp->GetBodySb($sbResponseBody); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.JsonObject') $jResp = new COM("Chilkat.JsonObject"); $jResp->LoadSb($sbResponseBody); $jResp->EmitCompact = 0; print 'Response Body:' . "\n"; print $jResp->emit() . "\n"; $respStatusCode = $resp->StatusCode; print 'Response Status Code = ' . $respStatusCode . "\n"; if ($respStatusCode >= 400) { print 'Response Header:' . "\n"; print $resp->Header . "\n"; print 'Failed.' . "\n"; exit; } // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "id": 794, // "name": "Premium Quality", // "slug": "premium-quality-19", // "permalink": "https://example.com/product/premium-quality-19/", // "date_created": "2017-03-23T17:01:14", // "date_created_gmt": "2017-03-23T20:01:14", // "date_modified": "2017-03-23T17:01:14", // "date_modified_gmt": "2017-03-23T20:01:14", // "type": "simple", // "status": "publish", // "featured": false, // "catalog_visibility": "visible", // "description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>\n", // "short_description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>\n", // "sku": "", // "price": "24.54", // "regular_price": "24.54", // "sale_price": "", // "date_on_sale_from": null, // "date_on_sale_from_gmt": null, // "date_on_sale_to": null, // "date_on_sale_to_gmt": null, // "price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">$</span>24.54</span>", // "on_sale": false, // "purchasable": true, // "total_sales": 0, // "virtual": false, // "downloadable": false, // "downloads": [ // ], // "download_limit": -1, // "download_expiry": -1, // "external_url": "", // "button_text": "", // "tax_status": "taxable", // "tax_class": "", // "manage_stock": false, // "stock_quantity": null, // "stock_status": "instock", // "backorders": "no", // "backorders_allowed": false, // "backordered": false, // "sold_individually": false, // "weight": "", // "dimensions": { // "length": "", // "width": "", // "height": "" // }, // "shipping_required": true, // "shipping_taxable": true, // "shipping_class": "", // "shipping_class_id": 0, // "reviews_allowed": true, // "average_rating": "0.00", // "rating_count": 0, // "related_ids": [ // 479, // 387, // 22, // 463, // 396 // ], // "upsell_ids": [ // ], // "cross_sell_ids": [ // ], // "parent_id": 0, // "purchase_note": "", // "categories": [ // { // "id": 9, // "name": "Clothing", // "slug": "clothing" // }, // { // "id": 14, // "name": "T-shirts", // "slug": "t-shirts" // } // ], // "tags": [ // ], // "images": [ // { // "id": 792, // "date_created": "2017-03-23T14:01:13", // "date_created_gmt": "2017-03-23T20:01:13", // "date_modified": "2017-03-23T14:01:13", // "date_modified_gmt": "2017-03-23T20:01:13", // "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", // "name": "", // "alt": "" // }, // { // "id": 793, // "date_created": "2017-03-23T14:01:14", // "date_created_gmt": "2017-03-23T20:01:14", // "date_modified": "2017-03-23T14:01:14", // "date_modified_gmt": "2017-03-23T20:01:14", // "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", // "name": "", // "alt": "" // } // ], // "attributes": [ // ], // "default_attributes": [ // ], // "variations": [ // ], // "grouped_products": [ // ], // "menu_order": 0, // "meta_data": [ // ], // "_links": { // "self": [ // { // "href": "https://example.com/wp-json/wc/v3/products/794" // } // ], // "collection": [ // { // "href": "https://example.com/wp-json/wc/v3/products" // } // ] // } // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_created = new COM("Chilkat.DtObj"); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_created_gmt = new COM("Chilkat.DtObj"); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_modified = new COM("Chilkat.DtObj"); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_modified_gmt = new COM("Chilkat.DtObj"); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_on_sale_from = new COM("Chilkat.DtObj"); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_on_sale_from_gmt = new COM("Chilkat.DtObj"); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_on_sale_to = new COM("Chilkat.DtObj"); // For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.DtObj') $date_on_sale_to_gmt = new COM("Chilkat.DtObj"); $id = $jResp->IntOf('id'); $name = $jResp->stringOf('name'); $slug = $jResp->stringOf('slug'); $permalink = $jResp->stringOf('permalink'); $jResp->DtOf('date_created',0,$date_created); $jResp->DtOf('date_created_gmt',0,$date_created_gmt); $jResp->DtOf('date_modified',0,$date_modified); $jResp->DtOf('date_modified_gmt',0,$date_modified_gmt); $v_type = $jResp->stringOf('type'); $status = $jResp->stringOf('status'); $featured = $jResp->BoolOf('featured'); $catalog_visibility = $jResp->stringOf('catalog_visibility'); $description = $jResp->stringOf('description'); $short_description = $jResp->stringOf('short_description'); $sku = $jResp->stringOf('sku'); $price = $jResp->stringOf('price'); $regular_price = $jResp->stringOf('regular_price'); $sale_price = $jResp->stringOf('sale_price'); $jResp->DtOf('date_on_sale_from',0,$date_on_sale_from); $jResp->DtOf('date_on_sale_from_gmt',0,$date_on_sale_from_gmt); $jResp->DtOf('date_on_sale_to',0,$date_on_sale_to); $jResp->DtOf('date_on_sale_to_gmt',0,$date_on_sale_to_gmt); $price_html = $jResp->stringOf('price_html'); $on_sale = $jResp->BoolOf('on_sale'); $purchasable = $jResp->BoolOf('purchasable'); $total_sales = $jResp->IntOf('total_sales'); $virtual = $jResp->BoolOf('virtual'); $downloadable = $jResp->BoolOf('downloadable'); $download_limit = $jResp->IntOf('download_limit'); $download_expiry = $jResp->IntOf('download_expiry'); $external_url = $jResp->stringOf('external_url'); $button_text = $jResp->stringOf('button_text'); $tax_status = $jResp->stringOf('tax_status'); $tax_class = $jResp->stringOf('tax_class'); $manage_stock = $jResp->BoolOf('manage_stock'); $stock_quantity = $jResp->stringOf('stock_quantity'); $stock_status = $jResp->stringOf('stock_status'); $backorders = $jResp->stringOf('backorders'); $backorders_allowed = $jResp->BoolOf('backorders_allowed'); $backordered = $jResp->BoolOf('backordered'); $sold_individually = $jResp->BoolOf('sold_individually'); $weight = $jResp->stringOf('weight'); $dimensionsLength = $jResp->stringOf('dimensions.length'); $dimensionsWidth = $jResp->stringOf('dimensions.width'); $dimensionsHeight = $jResp->stringOf('dimensions.height'); $shipping_required = $jResp->BoolOf('shipping_required'); $shipping_taxable = $jResp->BoolOf('shipping_taxable'); $shipping_class = $jResp->stringOf('shipping_class'); $shipping_class_id = $jResp->IntOf('shipping_class_id'); $reviews_allowed = $jResp->BoolOf('reviews_allowed'); $average_rating = $jResp->stringOf('average_rating'); $rating_count = $jResp->IntOf('rating_count'); $parent_id = $jResp->IntOf('parent_id'); $purchase_note = $jResp->stringOf('purchase_note'); $menu_order = $jResp->IntOf('menu_order'); $i = 0; $count_i = $jResp->SizeOfArray('downloads'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('related_ids'); while ($i < $count_i) { $jResp->I = $i; $intVal = $jResp->IntOf('related_ids[i]'); $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('upsell_ids'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('cross_sell_ids'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('categories'); while ($i < $count_i) { $jResp->I = $i; $id = $jResp->IntOf('categories[i].id'); $name = $jResp->stringOf('categories[i].name'); $slug = $jResp->stringOf('categories[i].slug'); $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('tags'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('images'); while ($i < $count_i) { $jResp->I = $i; $id = $jResp->IntOf('images[i].id'); $jResp->DtOf('images[i].date_created',0,$date_created); $jResp->DtOf('images[i].date_created_gmt',0,$date_created_gmt); $jResp->DtOf('images[i].date_modified',0,$date_modified); $jResp->DtOf('images[i].date_modified_gmt',0,$date_modified_gmt); $src = $jResp->stringOf('images[i].src'); $name = $jResp->stringOf('images[i].name'); $alt = $jResp->stringOf('images[i].alt'); $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('attributes'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('default_attributes'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('variations'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('grouped_products'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('meta_data'); while ($i < $count_i) { $jResp->I = $i; $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('_links.self'); while ($i < $count_i) { $jResp->I = $i; $href = $jResp->stringOf('_links.self[i].href'); $i = $i + 1; } $i = 0; $count_i = $jResp->SizeOfArray('_links.collection'); while ($i < $count_i) { $jResp->I = $i; $href = $jResp->stringOf('_links.collection[i].href'); $i = $i + 1; } ?> |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.