wpwham / multi-order-for-woocommerce

8 stars 2 forks source link

getting suborder number from WC Order #3

Open samjco opened 5 years ago

samjco commented 5 years ago

Is there a function where I can get the suborder numbers from and WC order number?

pablo-sg-pacheco commented 5 years ago

Hello,

You can get the suborders from a main order like this: $suborders = get_post_meta( $order_id, Alg_MOWC_Order_Metas::SUB_ORDERS );

And to get the parent order id from a suborder you can do it like this: $main_order_id = get_post_meta( $suborder_id, Alg_MOWC_Order_Metas::PARENT_ORDER, true );

samjco commented 5 years ago

SO does this look right:

$order = new WC_Order( $order_id );
foreach ($order->get_items() as $item_key => $item_values):

    $formatted_meta_data = $item_values->get_formatted_meta_data('Alg_MOWC_Order_Metas::SUB_ORDERS', true);

    // Display the raw outputs (for testing)

    echo '<pre>'; 
    print_r($formatted_meta_data); 
    echo '</pre>';

endforeach;