Full stack developer - love to build digital products, SAAS
Woocommerce API Custom Taxonomies and Meta Fields
My Ecommerce project requires an import/export task between the new site on woocommerce and the old one. Woocommerce has provided an excellent API for all the stuff you might need. Thank you very much Woocommerce and Wordpress.
(I planned to buy this Woocommerce CSV importer plugin with its add-ons but I found that Woocommerce API provided me everything. I need to spend a little bit more time to save $70 :D).
However, Woo V3 API doesn’t provide product custom taxonomies and meta fields
when creating/updating/showing products. So you need to implement this feature within your plugin. Here is how I did it:
About my project:
I need to add custom taxonomies to the product including: Brand, Collection, Audience taxonomies. I also need to add 2 meta fields including: Product Color Swatch and Product’s related SKUs.
1/ You can put these functions into theme’s functions.php or inside your own plugin. I put these in my plugins for the current project.
2/ As you can find in the class-wp-api-products.php of Woocommerce, there are several filters and actions for modifying/showing product info:
On line 193, there is a filter for showing additional info of products:
On line 280 of this file, you can find the action hook for saving more information of the product when creating:
On line 398, there is an action hook for product editing:
3/ So, you only need to hook into these actions/filters. Here is the code