How do I use a combination of switch_to_blog() and wc_create_order()?
I'm looking for a way to create a WC order programmatically for a subsite in my multisite environment.
When I use the following, the order is created on the main site and not the subsite with ID 7:
switch_to_blog( 7 );
// Now we create the order
$bestelling = wc_create_order();
// Get orderid from order-to-be-made
$neworderid = trim( str_replace( '#', '', $bestelling-get_order_number() ) );
// Get product data
$occurences = $_POST['productids'];
foreach($occurences as $key = $value) {
// Add products
$product = wc_get_product($key);
$bestelling-add_product($product, $value);
}
// Set addresses
$bestelling-set_address( $billingaddress, 'billing' );
$bestelling-set_address( $shippingaddress, 'shipping' );
// Set payment gateway
$payment_gateways = WC()-payment_gateways-payment_gateways();
$bestelling-set_payment_method( $payment_gateways['bacs'] );
$bestelling-set_customer_note( $_POST['customer_message'] );
// Calculate totals
$bestelling-calculate_totals();
// Give Revamp status
$bestelling-update_status('revamped', 'This order has been made with the revamp tool.', TRUE);
do_action( 'woocommerce_checkout_order_processed', $neworderid );
restore_current_blog();
Can it be done this way or should I look at this from another angle? Thanks in advance :).
Topic woocommerce-offtopic switch-to-blog multisite Wordpress
Category Web