WooCommerce: Creating an order programmatically with a variable product


Last Update : 2023-09-22 UTC 08:58:39 AM

Answers of > WooCommerce: Creating an order programmatically with a variable product

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);

if you already have the variation_id you can just do this

$product_variation = new WC_Product_Variation($variation_id);
$order = wc_create_order();
foreach($product_variation->get_variation_attributes() as $attribute=>$attribute_value){
$order->add_product($product_variation, $product['quantity'], $args);

Current topics : WooCommerce: Creating an order programmatically with a variable product

Newly Added Questions

Similar Questions

Questions :

How To Group Array Key Value

Last Update : 2023-09-22 UTC 12:55:01 PM

Questions :

PhpStorm Warning For React Attributes In Jsx File With SCSS File

Last Update : 2023-09-22 UTC 12:54:41 PM

Questions :

Why Is The File Not Showing Up In Request.files And In Request.forms Instead?

Last Update : 2023-09-22 UTC 12:54:24 PM

Questions :

Proxying Assets From React App Directory In Slim Framework?

Last Update : 2023-09-22 UTC 12:54:16 PM

Questions :

Laravel 5.4 Can't Run “php Artisan Preset React” Comand

Last Update : 2023-09-22 UTC 12:53:57 PM

Questions :

How To Update Session Values Without Signing Out?

Last Update : 2023-09-22 UTC 12:53:49 PM

Questions :

Array Is Not Visible

Last Update : 2023-09-22 UTC 12:53:32 PM

Questions :

React Routing For Login Using Symfony

Last Update : 2023-09-22 UTC 12:53:12 PM

Questions :

Sanctum With React SPA Returning 419 Page Expired

Last Update : 2023-09-22 UTC 12:53:02 PM

Questions :

How Do I Import An Input String Into Another Page

Last Update : 2023-09-22 UTC 12:52:52 PM

© 2023 W3CODED - All Rights Reserved.