WooCommerce: How to update order quantities at checkout

I am trying to update order quantities at the checkout or when the order has been placed.

I can add custom meta with the following:

Read More
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );

function my_custom_checkout_field_update_order_meta( $order_id ) {
   update_post_meta( $order_id, 'My Field', sanitize_text_field( 'testdata' ) );
}

How can I target a specific products quantity meta?

Thanks

Related posts

Leave a Reply

1 comment

  1. Try to just use WC_Cart class:

    • First try to get a cart: WC()->cart or WC()->instance()->cart
    • Then use method set_quantity( $cart_item_key, $quantity).
      Important: $cart_item_key is not a product id, but an id in cart.
    • Check print_r or var_dump WC()->cart to understand.