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:
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
Try to just use
WC_Cart class
:WC()->cart
orWC()->instance()->cart
set_quantity( $cart_item_key, $quantity)
.Important:
$cart_item_key
is not a product id, but an id in cart.print_r
orvar_dump WC()->cart
to understand.