Marketplaces / WooCommerce Technical Sccope / WooCommerce Product Management / WooCommerce Taxonomy

WooCommerce Taxonomy

Version Date Created / Updated Notes
v1.0 Hristiyan Georgiev Initial version

All validations, triggers and standardizations are as per Taxonomy General requirements

The taxonomy represents product attributes, categories and brands. Which we want to store, map, validate and export from MCPro.Please note that in terms of UI and UX we always want to show the names, but with WooCommerce we always communicate with the ids.

Get Categories

API Call : GET /wp-json/wc/v3/products/categories API Docs: https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#list-all-product-categories

There is a possibility for pagination so we need to be able to handle this thorugh the page and per_page params. Default per_page is 10 but we want to increase it to 100.

Example response :

[
    {
        "id": 46,
        "name": "Accessories",
        "slug": "accessories",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": null,
        "menu_order": 0,
        "count": 9,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories/46",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories"
                }
            ]
        }
    },
    {
        "id": 265,
        "name": "Adapters/Cables",
        "slug": "adapters-cables",
        "parent": 46,
        "description": "",
        "display": "default",
        "image": null,
        "menu_order": 0,
        "count": 6,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories/265",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories"
                }
            ],
            "up": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories/46"
                }
            ]
        }
    },
    {
        "id": 110,
        "name": "Case",
        "slug": "case",
        "parent": 100,
        "description": "",
        "display": "default",
        "image": {
            "id": 6691,
            "date_created": "2018-12-31T00:14:20",
            "date_created_gmt": "2018-12-31T05:14:20",
            "date_modified": "2018-12-31T00:14:20",
            "date_modified_gmt": "2018-12-31T05:14:20",
            "src": "https://viprtech.com/wp-content/uploads/2018/12/gaming-desktop-600x600.png",
            "name": "gaming-desktop-600×600",
            "alt": ""
        },
        "menu_order": 0,
        "count": 1,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories/110",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories"
                }
            ],
            "up": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories/100"
                }
            ]
        }
    },
    {
        "id": 100,
        "name": "Parts",
        "slug": "parts",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": {
            "id": 6793,
            "date_created": "2019-01-06T02:31:35",
            "date_created_gmt": "2019-01-06T07:31:35",
            "date_modified": "2019-01-06T02:31:35",
            "date_modified_gmt": "2019-01-06T07:31:35",
            "src": "https://viprtech.com/wp-content/uploads/2019/01/Computer-Parts.jpg",
            "name": "Computer-Parts",
            "alt": ""
        },
        "menu_order": 0,
        "count": 1,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories/100",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/categories"
                }
            ]
        }
    }
]

We store the id and name.If a category has a parent that is not equal to 0, this means that this category is a sub-category and its parent category’s id is listed. In such case, we want to link both categories and store them as parent{id}>child{id}. (Example provided in the export file structure).

Get Attributes

API Call : GET /wp-json/wc/v3/products/attributes

API Docs : https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#list-all-product-attributes

There is a possibility for pagination so we need to be able to handle this thorugh the page and per_page params. Default per_page is 10 but we want to increase it to 100.

Example response :

[
    {
        "id": 18,
        "name": "Case",
        "slug": "pa_case",
        "type": "select",
        "order_by": "menu_order",
        "has_archives": true,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/18",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes"
                }
            ]
        }
    },
    {
        "id": 21,
        "name": "Color",
        "slug": "pa_color",
        "type": "avada_color",
        "order_by": "menu_order",
        "has_archives": false,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes"
                }
            ]
        }
    },
    {
        "id": 17,
        "name": "Operating System",
        "slug": "pa_os",
        "type": "select",
        "order_by": "menu_order",
        "has_archives": true,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/17",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes"
                }
            ]
        }
    }   
]

From the response we need to store the id and name . After getting the attributes, we need to get the attributes’ values which are called attribute terms in WooCommerce. We need to query every single id from the above response and store the possible values against it.

Get Attributes’ values

API Call : GET /wp-json/wc/v3/products/attributes/{id}/terms API Docs : https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#list-all-attribute-terms

There is a possibility for pagination so we need to be able to handle this thorugh the page and per_page params. Default per_page is 10 but we want to increase it to 100.

The {id} we pick from the previous response.

Example response :

[
    {
        "id": 272,
        "name": "Black",
        "slug": "black",
        "description": "",
        "menu_order": 0,
        "count": 10,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms/272",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms"
                }
            ]
        }
    },
    {
        "id": 273,
        "name": "Blue",
        "slug": "blue",
        "description": "",
        "menu_order": 0,
        "count": 1,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms/273",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms"
                }
            ]
        }
    },
    {
        "id": 275,
        "name": "Red",
        "slug": "red",
        "description": "",
        "menu_order": 0,
        "count": 1,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms/275",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms"
                }
            ]
        }
    },
    {
        "id": 274,
        "name": "White",
        "slug": "white",
        "description": "",
        "menu_order": 0,
        "count": 10,
        "_links": {
            "self": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms/274",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://viprtech.com/wp-json/wc/v3/products/attributes/21/terms"
                }
            ]
        }
    }
]

Again we only want to store the id and name

Get Brands

API Call : GET /wp-json/wc/v3/products/brands?per_page=100 API Docs : None

There is a possibility for pagination so we need to be able to handle this thorugh the page and per_page params. Default per_page is 10 but we want to increase it to 100.

Example response :

[
    {
        "id": 29,
        "name": "Apple",
        "slug": "apple",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": null,
        "menu_order": 0,
        "count": 0,
        "_links": {
            "self": [
                {
                    "href": "https://sociable-sable-b1ae91.instawp.xyz/wp-json/wc/v3/products/brands/29",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://sociable-sable-b1ae91.instawp.xyz/wp-json/wc/v3/products/brands"
                }
            ]
        }
    },
    {
        "id": 35,
        "name": "ASus",
        "slug": "asus",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": null,
        "menu_order": 0,
        "count": 0,
        "_links": {
            "self": [
                {
                    "href": "https://sociable-sable-b1ae91.instawp.xyz/wp-json/wc/v3/products/brands/35",
                    "targetHints": {
                        "allow": [
                            "GET",
                            "POST",
                            "PUT",
                            "PATCH",
                            "DELETE"
                        ]
                    }
                }
            ],
            "collection": [
                {
                    "href": "https://sociable-sable-b1ae91.instawp.xyz/wp-json/wc/v3/products/brands"
                }
            ]
        }
    }
]

From the response we want to store the id and name .

Taxonomy export file

All of the attributes are not related to a specific category and can be used for all categories. So in order to keep consistency with our standard taxonomy exports, we want to include all of the attributes in all of the categories when doing the export. This means that in our export file we will have the same attributes for every single category.

Please also note that none of the taxonomy properties is required, so we consider everything as optional (brands,categories,attributes etc.)

Much like BigCommerce, we will have different set of taxonomies for the different WooCommerce accounts too.So if we have a case with an instance with more than one WooCommerce account and taxonomies, we would like to export it in a single email with multiple files for the different accounts

In order to generate the taxonomy file we will need to create a new record in Taxonomy export with: Marketplace = WooCommerce Status = pending Category for Export = Possible values are “all”, (we can also specify which exact categories) OR “brands”

Email = email to which the file will be sent

We want to have a logic and if the user has selected 5 or more categories for export, we want to export them in a single zip file. This will be valid also if all categories are being exported. More details on taxonomies can be found here - Taxonomy General requirements .

Please find example file structure how it should look like after export.

Column Column Column Column
PrimaryCatName Category Path Attribute Values
Accessories Accessories Color Black Blue Red
Accessories Accessories Case MasterBox Lite 3.1 MasterBox Lite 3.1 TG ViprTech 180x1 ViprTech L06
Accessories Accessories Operating System None Windows 10 Pro Windows 7
Parts Parts Color Black Blue Red
Adapters/Cables Accessories > Adapters/Cables Included Cables DisplayPort DVI HDMI
Case Parts > Case Case MasterBox Lite 3.1 MasterBox Lite 3.1 TG ViprTech 180x1 ViprTech L06
Case Parts > Case Case MasterBox Lite 3.1 MasterBox Lite 3.1 TG ViprTech 180x1 ViprTech L06

Brands export file :

Brand name
Apple
ASus
Is this article helpful?
0 0 0