Title: get option value in php custom function
Last modified: June 4, 2019

---

# get option value in php custom function

 *  Resolved [antoniolupo.net](https://wordpress.org/support/users/antonioluponet/)
 * (@antonioluponet)
 * [7 years ago](https://wordpress.org/support/topic/get-option-value-in-php-custom-function/)
 * 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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fget-option-value-in-php-custom-function%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Pektsekye](https://wordpress.org/support/users/pektsekye/)
 * (@pektsekye)
 * [7 years ago](https://wordpress.org/support/topic/get-option-value-in-php-custom-function/#post-11604644)
 * 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](https://wordpress.org/support/users/antonioluponet/)
 * (@antonioluponet)
 * [7 years ago](https://wordpress.org/support/topic/get-option-value-in-php-custom-function/#post-11607286)
 * 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](http://188.165.235.57/visurewp/wp-content/uploads/2019/06/Cattura.png)
 * thank you again.
 *  Thread Starter [antoniolupo.net](https://wordpress.org/support/users/antonioluponet/)
 * (@antonioluponet)
 * [7 years ago](https://wordpress.org/support/topic/get-option-value-in-php-custom-function/#post-11611027)
 * 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.

 * ![](https://ps.w.org/product-options-for-woocommerce/assets/icon-256x256.png?
   rev=1892402)
 * [Simple Product Options for WooCommerce](https://wordpress.org/plugins/product-options-for-woocommerce/)
 * [Support Threads](https://wordpress.org/support/plugin/product-options-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/product-options-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/product-options-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/product-options-for-woocommerce/reviews/)

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 3 replies
 * 2 participants
 * Last reply from: [antoniolupo.net](https://wordpress.org/support/users/antonioluponet/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/get-option-value-in-php-custom-function/#post-11611027)
 * Status: resolved