Hello,
When the order is complete the selected options are saved as order meta:
wc_add_order_item_meta($order_item_id, $value['name'], $value['value']);
If know the $orderId you can get all the order item ids:
$order = wc_get_order( $order_id );
foreach ($order->get_items() as $item_id => $item_data) {
}
Then if you know the order item id you can get the selected value for your option:
$selectedOptionValue = wc_get_order_item_meta($itemId, 'selected_option_name_here');
Stanislav
thank you for your quick response.
Anyway I can’t manage to get the value. Have I to put “Option Title” value in your code where you wrote ‘selected_option_name_here’?
Here is my code in thank-you page:
foreach ($order->get_items() as $item_id => $item_data) {
$selectedOptionValue = wc_get_order_item_meta($itemId, 'tipo_visura');
echo $selectedOptionValue.'<br>';
}
Whith this code I only get ‘<br>’ in thank you page.
In my product page i put ‘tipo_visura’ as option title in Custom Option section.
screenshot: http://188.165.235.57/visurewp/wp-content/uploads/2019/06/Cattura.png
thank you again.
I solved, there was a different name for $item_id variable inside the foreach cycle.
The correct code is:
foreach ($order->get_items() as $item_id => $item_data) {
$selectedOptionValue = wc_get_order_item_meta($item_id, 'tipo_visura');
echo $selectedOptionValue.'<br>';
}
Thank you very much again