numbers get - Woocommerce - add serial to products in orders

2 Answers

add extra meta for orders in woocommerce

The 2017 way

Building on Mo Saeedi answer, I believe this snippet is more in line with the new CRUD approach introduced by WooCommerce 3.0:

add_action('woocommerce_checkout_update_order_meta',function( $order_id, $posted ) {
    $order = wc_get_order( $order_id );
    $order->update_meta_data( 'my_custom_meta_key', 'my data' );
} , 10, 2);

See also this threads on the WordPress forums:

tags by id

I am looking for a way to add a serial number to each sold product, in the order display in WooCommerce. What I need is a manual solution, where the S/N of the sent product is added to the order before the package is sent. I have tried to show it on the following picture:

Originally, I thought about implementing it as a product meta (without really knowing how) but I realized that product metas can only be altered when the order is set on hold and not while processing.

Any ideas aboout how to proceed? Thanks already!

The 2016 way:

add_action('woocommerce_checkout_update_order_meta',function( $order_id, $posted ) {  
    update_post_meta( $order_id, 'my_custom_meta_key', 'my data' );  
} , 10, 2);
  • $order_id is the id of the order, which is stored as a custom post type
  • $posted is all the data from $_POST