Ich versuche, Produktvariationen mit der Funktion add_product() von woocommerce hinzuzufügen.So verwenden Sie die Funktion add_product für Variationen in Woocommerce
Aber jedes Mal füge ich das Variationsprodukt hinzu. Es fügt nur das Elternprodukt und nicht die Variation hinzu.
$product_id = 40;
$variation_id = 42;
$quantity = 1;
$variation_name = color;
$variation_option = red;
$args = array(
'attribute_'.$variation_name => $variation_option,
);
$order = wc_create_order();
$order->add_product(get_product($product_id), $quantity, $args);
Ich habe auch schon versucht, diese, die auch nicht
$order->add_product(get_product($variation_id), $quantity, $args);
Ich habe die Variation id, Attribut, Name und Option verdoppelt haben nicht funktioniert.
haben Sie versucht, '$ order-> add_product (wc_get_product ($ variation_id), $ Menge, $ args);' – Reigel