Last Update : 2023-09-22 UTC 08:58:39 AM
Is there something I'm missing, or a better w3coded creating product way to create an order with a variable w3coded creating product product?,I'm trying to create an order w3coded creating product programmatically. Using wc_create_order() this w3coded creating product is pretty straightforward:, w3coded creating product w3coded creating product Meta Stack w3coded creating product Overflow w3coded creating product ,Stack Overflow en español
In total, my working code now looks like this:
$membershipProduct = new WC_Product_Variable(100);
$theMemberships = $membershipProduct->get_available_variations();
$variationsArray = array();
foreach ($theMemberships as $membership) {
if ($membership['sku'] == $chosenVariation) {
$variationID = $membership['variation_id'];
$variationsArray['variation'] = $membership['attributes'];
}
}
if ($variationID) {
$varProduct = new WC_Product_Variation($variationID);
$order = wc_create_order();
$order->add_product($varProduct, 1, $variationsArray);
$order->calculate_totals();
}
if you already have the variation_id you can just do this
$product_variation = new WC_Product_Variation($variation_id);
$order = wc_create_order();
$args=array();
foreach($product_variation->get_variation_attributes() as $attribute=>$attribute_value){
$args['variation'][$attribute]=$attribute_value;
}
$order->add_product($product_variation, $product['quantity'], $args);
Last Update : 2023-09-22 UTC 12:54:41 PM
Last Update : 2023-09-22 UTC 12:54:24 PM
Last Update : 2023-09-22 UTC 12:54:16 PM
Last Update : 2023-09-22 UTC 12:53:57 PM
Last Update : 2023-09-22 UTC 12:53:49 PM
Last Update : 2023-09-22 UTC 12:53:02 PM
Last Update : 2023-09-22 UTC 12:52:52 PM