Title: Add option from function php
Last modified: August 26, 2019

---

# Add option from function php

 *  Resolved [lukiano880](https://wordpress.org/support/users/lukiano880/)
 * (@lukiano880)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/add-option-from-function-php/)
 * Hi. I would like to manage (add / remove) the custom options of some specific
   products, from a form, outside the product editing page.
    Probably a form in 
   my own custom plugin. Do you think it is possible to obtain the values in a php
   function? Or maybe it would be better to work directly with the database? Any
   suggestions will be appreciated. Thank you.

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

 *  Plugin Author [Pektsekye](https://wordpress.org/support/users/pektsekye/)
 * (@pektsekye)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/add-option-from-function-php/#post-11867851)
 * Hello,
 * If you can access the Pektsekye_ProductOptions_Model_Option class:
 *     ```
       include_once(Pektsekye_PO()->getPluginPath() . 'Model/Option.php');		
       $optionModel = new Pektsekye_ProductOptions_Model_Option();
       ```
   
 * To get all options of a product:
 *     ```
       $productOptions = $optionModel->getProductOptions($productId);
       ```
   
 * To create a new text option:
 *     ```
       $option = array(
         'option_id' => -1,
         'title' => "Choose Date",
         'type' => 'field',
         'required' => 1,
         'sort_order' => 1
       );
       $optionModel->saveOptions($productId, array($option));    
       $optionId = $wpdb->insert_id;
       ```
   
 * To create a new drop-down option:
 *     ```
       $option = array(
         'option_id' => -1,
         'title' => "Option title",
         'type' => 'drop_down',
         'required' => 1,
         'sort_order' => 1,
         'values' => array(array(
           'value_id' => -1,
           'title' => 'Value title 1',
           'price' => 0,
           'sort_order' => 0
         ))
       );
       $optionModel->saveOptions($productId, array($option));    
       $optionId = $wpdb->insert_id;
       ```
   
 * Available option types:
    drop_down, radio, checkbox, multiple, field, area
 * To update an option:
 *     ```
       $option = array(
         'option_id' => 567,
         'title' => "Option title",
         'type' => 'drop_down',
         'required' => 1,
         'sort_order' => 1,
         'values' => array(array(
           'value_id' => 233,
           'title' => 'Value title 1',
           'price' => 0,
           'sort_order' => 0
         ))
       );
       $optionModel->saveOptions($productId, array($option));    
       ```
   
 * To delete an option:
 *     ```
       $optionModel->deleteOption($optionId);
       ```
   
 * Or save it with is_delete = 1
 *     ```
       $option = array(
         'option_id' => 233,
         'is_delete' => 1
       );
       $optionModel->saveOptions($productId, array($option));    
       ```
   
 * Also you can edit/insert/delete the data directly in the database tables:
    wp_pofw_product_option
   wp_pofw_product_option_value
 * Stanislav
 *  [nbtv](https://wordpress.org/support/users/nbtv/)
 * (@nbtv)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/add-option-from-function-php/#post-12197562)
 * what we have to edit to get two column of one option since I have 24 rows of 
   check boxes?
    -  This reply was modified 6 years, 5 months ago by [nbtv](https://wordpress.org/support/users/nbtv/).

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

The topic ‘Add option from function php’ 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/)

 * 2 replies
 * 1 participant
 * Last reply from: [nbtv](https://wordpress.org/support/users/nbtv/)
 * Last activity: [6 years, 5 months ago](https://wordpress.org/support/topic/add-option-from-function-php/#post-12197562)
 * Status: resolved