I'm trying to assign an order's product SKU to a custom value, like this:
add_action( 'woocommerce_thankyou', 'change_value' );
function change_value( $order_id ) {
$item_sku = '';
$order = wc_get_order( $order_id );
foreach ($order->get_items() as $item) {
$product = wc_get_product($item->get_product_id());
$item_sku = $product->get_sku();
}
update_post_meta( $order_id, 'custom_value', $item_sku );
}
However, I can't make it work and I can't find anything about how to update a custom value from Metabox in a similar way to this. Can you help me? Thanks!