Datafeedr API Customisation_
Datafeedr API integration for WooCommerce
Project Details_
Project_
WooCommerce
Project Roles:
Project Tech:
The Datafeedr plugin reset product categories, after an update, back to default categories when the product sets were defined. There is a way to fix this.
Chris from https://fashionandbusiness.nl approach me with a little issue they had when they update their products via the Datafeedr API. The Datafeedr API pulls in a collection of selected products into the WooCommerce store and creates and updates the products automatically. If the products are selected and a group from a list under the product sets (Datafeedr product setup page) they can be assigned default categories.
The problem was that they, fashionandbusiness.nl, only manually define these categories for their products after it was added under Products in WooCommerce. So each time the products are updated via the Datafeedr API these categories will get replaced by the default categories. This will make sense for a lot of users to define the product categories beforehand, but through the years I have experienced first hand each business is a bit different. What works for you, might not work for someone else.
Datafeedr makes it easy to build and embed an affiliate store into your WordPress blog. No programming required. Promote products from thousands of merchants. Your store automatically updates. https://www.datafeedr.com/
My first approach was to unset the default taxonomy's term ids been passed in the update process so that it does not revert back to the default categories.
Just a quick explanation about taxonomies and terms. Terms are Categories and many terms can belong to one taxonomy. For example.: Taxonomy: Product, for example the Product 'category' lets you group posts together by sorting them into various categories(terms). Terms: Electronics, with child terms: Television, Camera.
There were some issues with some products not updating correctly after I applied my code. In the second attempt, after knowing the code of the plugin a bit better, I found a hook in the plugin that triggers the update method, the method that removes the existing custom defined product categories. These are the categories we are trying to keep and do not want it to be replaced by the default ones. On this hook, I created a function that stores all the current set term ids for a product under a custom metadata field of that specific post in the database. The post itself is not removed in the process, only the terms by default. So when the update is performed I hooked into the update method and unset the default taxonomy terms that is about to be saved in the update process. Perform a database query for the temporarily stored term ids (I previously saved in the database) and add them to the array that is going to pass the newly updated content for the post (product). So, in short, the current taxonomy terms (categories) are added back as they were set manually before.