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?
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