Woocommerce create variable product programmatically

Question

TL;DR

When creating a variable product programmatically with variations, the variations are not shown, not in the product and not in the attributes tab.

enter image description here


THE PROBLEM

I created an API that receives a JSON object, with that object I want to create variable products (thats the only type I will create), I have followed a few stackoverflow sources

Create programmatically a variable product and two new attributes in WooCommerce

Create programmatically a WooCommerce product variation with new attribute values

and with every single one I had the same problem, The attribute would be created (I saw it in the DB) but it would not show in product or in attributes, only after a added the attribute manually will it show with the terms I created

enter image description here

This doesn’t help because the products still don’t have/show the attributes/variations and I can’t manually create them because I dont know when my API will receive the JSON and I dont know what attributes I will receive.

There was a youtube video

WooCommerce Add Variable Product and Variations Programmatically – Pricode

That came close to a solution, with the help of the video I was able to create a variable product with variations, but in that way the product did not use the attributes taxonomy.

enter image description here

Any help would be greatly appreciated!

Thank you for your time and have a great day!

0
Buttered_Toast 2 months 0 Answers 5 views 0

Leave an answer