2016-06-13 12 views
-1

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.

+0

haben Sie versucht, '$ order-> add_product (wc_get_product ($ variation_id), $ Menge, $ args);' – Reigel

Antwort

1

denke ich etwas falsch Pass args Parameter dieses versuchen

$product_id = 132; 
$quantity = 1; 

$args = array( 
'variation' => array('attribute_color' => 'red'), 
); 

$order = wc_create_order(); 
$order->add_product(get_product($product_id), $quantity, $args); 
//$order->set_total(15.50); // set total amount for paid order including tax, fees etc. 
+0

Großen das funktioniert. Vielen Dank!! –

Verwandte Themen