I am using the WoocommerceNET Library (Nuget Link) to develop a desktop app that will sync the products from the ERP database to the Woocommerce eshop database.

I added attributes size and color with values eg red,green,blue and s,m,l,xl. Now I need to create the variations.

Tried this:

  List<VariationAttribute> vatrib = new List<VariationAttribute>()
            { new VariationAttribute() { name="Color",option="GREEN" },
              new VariationAttribute() { name="size",option="L" } };

       Variation var = new Variation() {
                             regular_price=1.0M,
                             visible=true,
                             attributes=vatrib,
                             stock_quantity=5,
                             manage_stock=true
                        };
       //... repeat for each variation ....

       List<Variation> varis = new List<Variation>();
       varis.Add(var);
       varis.Add(var1);
       varis.Add(var2);  ... and so on for all variations

       Product p = new Product()
                {
                    //options ....
                    type = "variable",
                    manage_stock = true,
                    in_stock = true,
                    attributes=attribs,
                    variations=varis,
                };
                await wc.Product.Add(p);

But i get an error

Cannot implicitly convert type
‘System.Collections.Generic.List’
to ‘System.Collections.Generic.List’

It looks like the variation attribute of Product is a List that contain the variations ids.

How can I add a new product with variations for color and size?

Read more here: Adding Product variations with multiple attributes Woocommerce.NET and C#


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: