Visual FoxPro
Visual FoxPro
WooCommerce Create a Product
See more WooCommerce Examples
Demonstrates how to create a new product in WooCommerce.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL loDate_created
LOCAL loDate_created_gmt
LOCAL loDate_modified
LOCAL loDate_modified_gmt
LOCAL loDate_on_sale_from
LOCAL loDate_on_sale_from_gmt
LOCAL loDate_on_sale_to
LOCAL loDate_on_sale_to_gmt
LOCAL lnIntVal
LOCAL lcSrc
LOCAL lcAlt
LOCAL lcHref
LOCAL lnId
LOCAL lcName
LOCAL lcSlug
LOCAL lcPermalink
LOCAL lcV_type
LOCAL lcStatus
LOCAL lnFeatured
LOCAL lcCatalog_visibility
LOCAL lcDescription
LOCAL lcShort_description
LOCAL lcSku
LOCAL lcPrice
LOCAL lcRegular_price
LOCAL lcSale_price
LOCAL lcPrice_html
LOCAL lnOn_sale
LOCAL lnPurchasable
LOCAL lnTotal_sales
LOCAL lnVirtual
LOCAL lnDownloadable
LOCAL lnDownload_limit
LOCAL lnDownload_expiry
LOCAL lcExternal_url
LOCAL lcButton_text
LOCAL lcTax_status
LOCAL lcTax_class
LOCAL lnManage_stock
LOCAL lcStock_quantity
LOCAL lcStock_status
LOCAL lcBackorders
LOCAL lnBackorders_allowed
LOCAL lnBackordered
LOCAL lnSold_individually
LOCAL lcWeight
LOCAL lcDimensionsLength
LOCAL lcDimensionsWidth
LOCAL lcDimensionsHeight
LOCAL lnShipping_required
LOCAL lnShipping_taxable
LOCAL lcShipping_class
LOCAL lnShipping_class_id
LOCAL lnReviews_allowed
LOCAL lcAverage_rating
LOCAL lnRating_count
LOCAL lnParent_id
LOCAL lcPurchase_note
LOCAL lnMenu_order
LOCAL i
LOCAL lnCount_i
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
* Implements the following CURL command:
* curl -X POST https://example.com/wp-json/wc/v3/products \
* -u consumer_key:consumer_secret \
* -H "Content-Type: application/json" \
* -d '{
* "name": "Premium Quality",
* "type": "simple",
* "regular_price": "21.99",
* "description": "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.",
* "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
* "categories": [
* {
* "id": 9
* },
* {
* "id": 14
* }
* ],
* "images": [
* {
* "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
* },
* {
* "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
* }
* ]
* }'
* Use the following online tool to generate HTTP code from a CURL command
* Convert a cURL Command to HTTP Source Code
loHttp.BasicAuth = 1
loHttp.Login = "consumer_key"
loHttp.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.
* {
* "name": "Premium Quality",
* "type": "simple",
* "regular_price": "21.99",
* "description": "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.",
* "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
* "categories": [
* {
* "id": 9
* },
* {
* "id": 14
* }
* ],
* "images": [
* {
* "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
* },
* {
* "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
* }
* ]
* }
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("name","Premium Quality")
loJson.UpdateString("type","simple")
loJson.UpdateString("regular_price","21.99")
loJson.UpdateString("description","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.")
loJson.UpdateString("short_description","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.")
loJson.UpdateInt("categories[0].id",9)
loJson.UpdateInt("categories[1].id",14)
loJson.UpdateString("images[0].src","http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg")
loJson.UpdateString("images[1].src","http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg")
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpJson("POST","https://example.com/wp-json/wc/v3/products",loJson,"application/json",loResp)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
RELEASE loResp
CANCEL
ENDIF
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
* 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": "21.99",
* "regular_price": "21.99",
* "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>21.99</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": [
* 53,
* 40,
* 56,
* 479,
* 99
* ],
* "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
loDate_created = CreateObject('Chilkat.DtObj')
loDate_created_gmt = CreateObject('Chilkat.DtObj')
loDate_modified = CreateObject('Chilkat.DtObj')
loDate_modified_gmt = CreateObject('Chilkat.DtObj')
loDate_on_sale_from = CreateObject('Chilkat.DtObj')
loDate_on_sale_from_gmt = CreateObject('Chilkat.DtObj')
loDate_on_sale_to = CreateObject('Chilkat.DtObj')
loDate_on_sale_to_gmt = CreateObject('Chilkat.DtObj')
lnId = loJResp.IntOf("id")
lcName = loJResp.StringOf("name")
lcSlug = loJResp.StringOf("slug")
lcPermalink = loJResp.StringOf("permalink")
loJResp.DtOf("date_created",0,loDate_created)
loJResp.DtOf("date_created_gmt",0,loDate_created_gmt)
loJResp.DtOf("date_modified",0,loDate_modified)
loJResp.DtOf("date_modified_gmt",0,loDate_modified_gmt)
lcV_type = loJResp.StringOf("type")
lcStatus = loJResp.StringOf("status")
lnFeatured = loJResp.BoolOf("featured")
lcCatalog_visibility = loJResp.StringOf("catalog_visibility")
lcDescription = loJResp.StringOf("description")
lcShort_description = loJResp.StringOf("short_description")
lcSku = loJResp.StringOf("sku")
lcPrice = loJResp.StringOf("price")
lcRegular_price = loJResp.StringOf("regular_price")
lcSale_price = loJResp.StringOf("sale_price")
loJResp.DtOf("date_on_sale_from",0,loDate_on_sale_from)
loJResp.DtOf("date_on_sale_from_gmt",0,loDate_on_sale_from_gmt)
loJResp.DtOf("date_on_sale_to",0,loDate_on_sale_to)
loJResp.DtOf("date_on_sale_to_gmt",0,loDate_on_sale_to_gmt)
lcPrice_html = loJResp.StringOf("price_html")
lnOn_sale = loJResp.BoolOf("on_sale")
lnPurchasable = loJResp.BoolOf("purchasable")
lnTotal_sales = loJResp.IntOf("total_sales")
lnVirtual = loJResp.BoolOf("virtual")
lnDownloadable = loJResp.BoolOf("downloadable")
lnDownload_limit = loJResp.IntOf("download_limit")
lnDownload_expiry = loJResp.IntOf("download_expiry")
lcExternal_url = loJResp.StringOf("external_url")
lcButton_text = loJResp.StringOf("button_text")
lcTax_status = loJResp.StringOf("tax_status")
lcTax_class = loJResp.StringOf("tax_class")
lnManage_stock = loJResp.BoolOf("manage_stock")
lcStock_quantity = loJResp.StringOf("stock_quantity")
lcStock_status = loJResp.StringOf("stock_status")
lcBackorders = loJResp.StringOf("backorders")
lnBackorders_allowed = loJResp.BoolOf("backorders_allowed")
lnBackordered = loJResp.BoolOf("backordered")
lnSold_individually = loJResp.BoolOf("sold_individually")
lcWeight = loJResp.StringOf("weight")
lcDimensionsLength = loJResp.StringOf("dimensions.length")
lcDimensionsWidth = loJResp.StringOf("dimensions.width")
lcDimensionsHeight = loJResp.StringOf("dimensions.height")
lnShipping_required = loJResp.BoolOf("shipping_required")
lnShipping_taxable = loJResp.BoolOf("shipping_taxable")
lcShipping_class = loJResp.StringOf("shipping_class")
lnShipping_class_id = loJResp.IntOf("shipping_class_id")
lnReviews_allowed = loJResp.BoolOf("reviews_allowed")
lcAverage_rating = loJResp.StringOf("average_rating")
lnRating_count = loJResp.IntOf("rating_count")
lnParent_id = loJResp.IntOf("parent_id")
lcPurchase_note = loJResp.StringOf("purchase_note")
lnMenu_order = loJResp.IntOf("menu_order")
i = 0
lnCount_i = loJResp.SizeOfArray("downloads")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("related_ids")
DO WHILE i < lnCount_i
loJResp.I = i
lnIntVal = loJResp.IntOf("related_ids[i]")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("upsell_ids")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("cross_sell_ids")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("categories")
DO WHILE i < lnCount_i
loJResp.I = i
lnId = loJResp.IntOf("categories[i].id")
lcName = loJResp.StringOf("categories[i].name")
lcSlug = loJResp.StringOf("categories[i].slug")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("tags")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("images")
DO WHILE i < lnCount_i
loJResp.I = i
lnId = loJResp.IntOf("images[i].id")
loJResp.DtOf("images[i].date_created",0,loDate_created)
loJResp.DtOf("images[i].date_created_gmt",0,loDate_created_gmt)
loJResp.DtOf("images[i].date_modified",0,loDate_modified)
loJResp.DtOf("images[i].date_modified_gmt",0,loDate_modified_gmt)
lcSrc = loJResp.StringOf("images[i].src")
lcName = loJResp.StringOf("images[i].name")
lcAlt = loJResp.StringOf("images[i].alt")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("attributes")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("default_attributes")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("variations")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("grouped_products")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("meta_data")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("_links.self")
DO WHILE i < lnCount_i
loJResp.I = i
lcHref = loJResp.StringOf("_links.self[i].href")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("_links.collection")
DO WHILE i < lnCount_i
loJResp.I = i
lcHref = loJResp.StringOf("_links.collection[i].href")
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp
RELEASE loDate_created
RELEASE loDate_created_gmt
RELEASE loDate_modified
RELEASE loDate_modified_gmt
RELEASE loDate_on_sale_from
RELEASE loDate_on_sale_from_gmt
RELEASE loDate_on_sale_to
RELEASE loDate_on_sale_to_gmt