fbpx

Datafeedr API Customisation

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.

Click on the images to enlarge.

Posted in projects

Water Contaminate Report App build for Web-based and Android platform using React & NodeJS

Front-end Description I decided that React(my ultimate new platform of choice) would be a perfect fit for this project as a lot of API calls would need to be processed and we are going to render different screens based on user interaction. A more refined app-state was also required to keep track of the current…
Read More
single page donations app

Single Page Application – Donate to a good cause with a Payment Gateway and Email Transactions.

Front-End Description I decided to build this Single Page Application, with vanilla JavaScript ES5 & ES6 syntax, with a custom self-contained STATE. A STATE is like a memory place-holder for when you need to store data that you want to reuse. It also keeps track of login sessions. Most importantly is to keep track of…
Read More
JavaScript App Desktop API

Small JavaScript APP, VIN number lookup for Proficient Auto Transport

There is no GO BIG or GO HOME here. I also enjoy working on small projects and cater to smaller businesses! Not just that, it is because that small client of today can be a BIG client down the road…#facts   Technical Details. Build a small basic JavaScript App that connects to an external API…
Read More
×
0 Shares
Share
Share
Tweet