• How can i get the addons for an automated json export.

    i need to export the selected topping with the product.

    where can i get it? how is it saved within the order?

    best regards.

    🙂

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

    (@pektsekye)

    Hello,

    The selected product options are saved as order item meta:

    
    wc_add_order_item_meta($item_id, $value['name'], $value['value']);
    

    To make it easier you can replace the code:

    
    foreach ($selectedValues as $value){
      wc_add_order_item_meta($item_id, $value['name'], $value['value']);
    }
    

    with:

    
    $names = array();
    foreach ($selectedValues as $value){
      wc_add_order_item_meta($item_id, $value['name'], $value['value']);
      $names[] = $value['name'];
    }
    wc_add_order_item_meta($item_id, '_pofw_option_names', implode('|' ,$names));
    

    Then you can get selected options of some order with this code:

    
    $order = wc_get_order($post->ID);
    foreach ($order->get_items() as $item_id => $item) {
    
      if (!isset($item['item_meta']['_pofw_option_names'])){
        continue;
      }
      
      $meta = $item['item_meta'];
      $optionNames = explode('|', $item['item_meta']['_pofw_option_names']);
    
      foreach ($optionNames as $name){
        if (isset($item['item_meta'][$name]))
          echo $name .' : '. $item['item_meta'][$name] . '<br/>';
      }
    
    }
    

    Stanislav

    Thread Starter thx4jh

    (@thx4jh)

    heyhey. in which file do i find the code to replace it? thx! is there an option to export the “topping” as standalone? so pommes 2 money and ketchup 0,5 money?

    Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    >in which file do i find the code to replace it

    My previous message is about the file:
    wp-content/plugins/product-options-for-woocommerce/Model/Observer.php

    You can get the price of the selected option value with code like this:

    
    foreach ($this->getProductOptions($productId) as $oId => $option){
          if (!isset($selectedValues[$oId])){
            continue;
          }
    
          $selectedValue = $selectedValues[$oId];
          
          $value = '';        
          if ($option['type'] == 'drop_down' || $option['type'] == 'radio'){
            if (is_array($selectedValue)){
              continue;
            }
            $vId = (int) $selectedValue;
            if (isset($option['values'][$vId])){
              $valueTitle = $option['values'][$vId]['title'];
              $valuePrice = $option['values'][$vId]['price'];
            }
          }
    }
    

    Stanislav

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

The topic ‘AddOn GET’ is closed to new replies.