• Resolved antoniolupo.net

    (@antonioluponet)


    Hello,
    I use your plugin because is very good and easy to use and configure.

    Now I need to get the value selected by a radio input in a custom function when i’m in thank-you page. I already searched if that value is stored in post metas but i think it’s not.

    Is there a way to get the value? Could you give me a example script? I need to execute different script depending on choosen value.

    Thank you.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Pektsekye

    (@pektsekye)

    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

    Thread Starter antoniolupo.net

    (@antonioluponet)

    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: https://188.165.235.57/visurewp/wp-content/uploads/2019/06/Cattura.png

    thank you again.

    Thread Starter antoniolupo.net

    (@antonioluponet)

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get option value in php custom function’ is closed to new replies.