My Scenario is simple:
I have Attributes: Size & Color with Variations: Size(Small,Medium,Large) & Color(Red,Blue) I have add these attributes to a specific ProductID.
How I can add the variation (Small/Red) to this ProductID on woocommerce using vb.net?
CodePudding user response:
I solved it with the code below. it's important to create an Async Sub for this code. I add my code to the "btn_Product_Variations" button's Click event.
Private Async Sub btn_Product_Variations_Click(sender As Object, e As EventArgs) Handles btn_Product_Variations.Click
Dim VariationAttr As New WooCommerceNET.WooCommerce.v3.VariationAttribute With {
.id = Attribute_Color_ID,
.[option] = "Red"}
Dim VariationAttr1 As New WooCommerceNET.WooCommerce.v3.VariationAttribute With {
.id = Attribute_Size_ID,
.[option] = "Small"}
Dim lstIVariationAttr() As WooCommerceNET.WooCommerce.v3.VariationAttribute = {VariationAttr, VariationAttr1}
Dim lstOfVariationAttr As List(Of VariationAttribute) = New List(Of VariationAttribute)(lstIVariationAttr)
Dim ProductVariations As New WooCommerceNET.WooCommerce.v3.Variation With {
.attributes = lstOfVariationAttr}
Dim result As New WooCommerceNET.WooCommerce.v3.Variation
result = Await wc.Product.Variations.Add(ProductVariations, ProductID)
MsgBox("Done! New Product_Variation_ID=" & result.id.ToString)
End Sub