• Resolved lukiano880

    (@lukiano880)


    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

    (@pektsekye)

    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

    what we have to edit to get two column of one option since I have 24 rows of check boxes?

    • This reply was modified 4 years, 12 months ago by nbtv.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add option from function php’ is closed to new replies.