Page 1 of 1

Woocommercenet Auswählen eines Produktvariationsattributs

Posted: 21 Feb 2025, 00:02
by Anonymous
Ich kann Produktattribute und Produktvariationen hinzufügen. Wie wählen Sie die Standardattribute für eine Variation aus? Die obere Reihe des Bildes unten zeigt, was ich erreichen möchte. Die Optionen für die Drop -Downs sind in den Produktattributen festgelegt.

Code: Select all

 var variationList = new List();
List default_attributes = new List();

variationList.Add(new Variation
{
regular_price = 33.3,
price = 23.99,
description =  "Some product " ,
weight = 1.2,
sku = "SKU num"
});

List myVarAttrList = new List();
VariationAttribute varAttrib = new VariationAttribute();
varAttrib.option = "Not a Sample";
varAttrib.name = "Sample";

myVarAttrList.Add(varAttrib);

foreach (Variation variat in variationList)
{
//  variat.attributes.Add(varAttrib);  this causes and Object reference not set exception
variat.attributes = myVarAttrList;

var addVar = wc.Product.Variations.Add(variat, Convert.ToUInt32(RecID));

}