Update orderline meta (qty)
-
Hi,
I am trying to add meta-data to my orderline items.
But it looks like the “$quantity” output is not right, it is not taking the qty from the right product line?
Also what I actually want is that this meta data is being updated when an order is updated, not only when it is set to processsing.Do you have any idea what I am doing wrong?
function add_pakket_aantal_productline( $items, $order ) { foreach ( $order->get_items() as $item_id => $item ) { $quantity = $item->get_quantity(); $product_id = $item->get_product_id(); $product = wc_get_product($product_id); $step_value = $product->get_meta('_alg_wc_pq_step'); $pakket_aantal = $quantity / $step_value; $items = $order->get_items(); foreach ( $items as $item ) { $item->update_meta_data( '_pakketten', $pakket_aantal ); $item->save_meta_data(); } } } add_action( 'woocommerce_order_status_processing', 'add_pakket_aantal_productline', 10, 2 );
Best regards,
Olga
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Update orderline meta (qty)’ is closed to new replies.