get_meta(WCPA_ORDER_META_KEY);
if (is_array($meta_data) && count($meta_data)) {
foreach ($meta_data as $v) {
if (isset($v['meta_id']) && ($meta_id == $v['meta_id'])) {
return $v;
}
}
} else {
return false;
}
return false;
}
public function order_meta_plain($v, $show_price = true,$quantity=1) {
$field_price_multiplier = 1;
if (wcpa_get_option('show_field_price_x_quantity', false)) {
$field_price_multiplier = $quantity;
}
if (
(isset($v['form_data']->form_rules['pric_cal_option_once'])
&& $v['form_data']->form_rules['pric_cal_option_once'] === true)
|| (isset($v['form_data']->form_rules['pric_use_as_fee']) && $v['form_data']->form_rules['pric_use_as_fee'] === true) ||
(isset($v['is_fee']) && $v['is_fee'] === true)
) {
$field_price_multiplier = 1;
}
if ($v['type'] == 'file') {
if (isset($v['value']['url']) && $v['value']['url']) {
if ($v['price'] && $show_price) {
return $v['value']['file_name'] . ' | ' . $v['value']['url'] . ' | (' . wcpa_price($v['price']*$field_price_multiplier, 1) . ')';
} else {
return $v['value']['file_name'] . ' | ' . $v['value']['url'];
}
} else {
return '';
}
} else if ($v['type'] == 'image-group') {
if ($v['price'] && $show_price) {
return implode("\n", array_map(function($a, $b) use($field_price_multiplier) {
if ($a['i'] === 'other') {
if ($b) {
return __($a['label'] . ':', 'wcpa-text-domain') . ' ' . $a['value'] . ' | (' . wcpa_price($b*$field_price_multiplier, 1) . ')';
} else {
return __($a['label'] . ':', 'wcpa-text-domain') . ' ' . $a['value'];
}
} else {
if ($b) {
return $a['label'] . ' | ' . $a['image'] . ' | (' . wcpa_price($b*$field_price_multiplier, 1) . ')';
} else {
return $a['label'] . ' | ' . $a['image'];
}
}
}, $v['value'], $v['price']));
} else {
return implode("\n", array_map(function($a) {
if ($a['i'] === 'other') {
return __($a['label'] . ':', 'wcpa-text-domain') . ' ' . $a['value'];
} else {
return $a['label'] . ' | ' . $a['image'];
}
}, $v['value']));
}
} else if ($v['type'] == 'color-group') {
if ($v['price'] && $show_price) {
return implode("\n", array_map(function($a, $b) use($field_price_multiplier) {
if ($a['i'] === 'other') {
if ($b) {
return __($a['label'] . ':', 'wcpa-text-domain') . ' ' . $a['value'] . ' | (' . wcpa_price($b*$field_price_multiplier, 1) . ')';
} else {
return __($a['label'] . ':', 'wcpa-text-domain') . ' ' . $a['value'];
}
} else {
if ($b) {
return $a['label'] . ' | ' . $a['value'] . ' | ' . $a['color'] . ' | (' . wcpa_price($b*$field_price_multiplier, 1) . ')';
} else {
return $a['label'] . ' | ' . $a['value'] . ' | ' . $a['color'];
}
}
}, $v['value'], $v['price']));
} else {
return implode("\n", array_map(function($a) {
if ($a['i'] === 'other') {
return __($a['label'] . ':', 'wcpa-text-domain') . ' ' . $a['value'];
} else {
return $a['label'] . ' | ' . $a['value'] . ' | ' . $a['color'];
}
}, $v['value']));
}
} else if ($v['type'] == 'placeselector') {
$display = '';
if (!empty($v['value']['formated'])) {
$display = $v['value']['formated'] . "\n";
if (!empty($v['value']['splited']['street_number'])) {
$display .= __('Street address:', 'wcpa-text-domain') . ' ' . $v['value']['splited']['street_number'] . ' ' . $v['value']['splited']['route'] . "\n";
}
if (!empty($v['value']['splited']['locality'])) {
$display .= __('City:', 'wcpa-text-domain') . ' ' . $v['value']['splited']['locality'] . "\n";
}
if (!empty($v['value']['splited']['administrative_area_level_1'])) {
$display .= __('State:', 'wcpa-text-domain') . ' ' . $v['value']['splited']['administrative_area_level_1'] . "\n";
}
if (!empty($v['value']['splited']['postal_code'])) {
$display .= __('Zip code:', 'wcpa-text-domain') . ' ' . $v['value']['splited']['postal_code'] . "\n";
}
if (!empty($v['value']['splited']['country'])) {
$display .= __('Country:', 'wcpa-text-domain') . ' ' . $v['value']['splited']['country'] . "\n";
}
if (isset($v['value']['cords']['lat']) && !empty($v['value']['cords']['lat'])) {
$display .= __('Latitude:', 'wcpa-text-domain') . ' ' . $v['value']['cords']['lat'] . "\n";
$display .= __('Longitude:', 'wcpa-text-domain') . ' ' . $v['value']['cords']['lng'] . "\n";
}
}
return $display;
} else if (is_array($v['value'])) {
$is_ver_1_data = TRUE;
$first = current($v['value']);
if (isset($first['i'])) {
$is_ver_1_data = FALSE;
}
if ($is_ver_1_data) {
if ($v['price'] && $show_price) {
return implode("\n", array_map(function($a, $b) use($field_price_multiplier){
if ($b !== null && $b !== false) {
return $a . ' (' . wcpa_price($b*$field_price_multiplier, 1) . ')';
} else {
return $a;
}
}, $v['value'], $v['price']));
} else {
return implode("\n", $v['value']);
}
} else {
if (($v['price']) && $show_price) {
return implode("\n", array_map(function($a, $b) use($field_price_multiplier) {
if (($a['i'] === 'other')) {
return __($a['label'] . ':', 'wcpa-text-domain') . ' ' . $a['value'] . (($b !== null && $b !== false) ? ' (' . wcpa_price($b*$field_price_multiplier, 1) . ')' : '');
} else {
return $a['label'] . (($b !== null && $b !== false) ? ' (' . wcpa_price($b*$field_price_multiplier, 1) . ')' : '');
}
// if ($b) {
// return (($a['i'] === 'other') ? __($a['label'] . ':', 'wcpa-text-domain') . ' ' : '') . $a['label'] . ' (' . wcpa_price($b, 1) . ')';
// } else {
// return (($a['i'] === 'other') ? __('Other:', 'wcpa-text-domain') . ' ' : '') . $a['label'];
// }
}, $v['value'], $v['price']));
} else {
return trim(array_reduce($v['value'], function($a, $b) {
if ($b['i'] === 'other') {
return $a . "\n" . __($b['label'] . ':', 'wcpa-text-domain') . $b['value'];
} else {
return $a . "\n" . $b['label'];
}
}), "\n");
}
}
} else {
if ($v['price'] && $show_price) {
return $v['value'] . ' (' . wcpa_price($v['price']*$field_price_multiplier, 1) . ')';
} else {
return $v['value'];
}
}
}
public function display_item_meta($html, $item, $args) {
$html = str_replace('' . WCPA_EMPTY_LABEL . ':', '', $html);
return str_replace(WCPA_EMPTY_LABEL . ':', '', $html);
}
public function display_meta_value($display_value, $meta=null, $item=null) {
if($item!=null && $meta!==null){
$wcpa_data = $this->wcpa_meta_by_meta_id($item, $meta->id);
}else{
$wcpa_data = false;
}
$out_display_value = $display_value;
if ($wcpa_data) {
$this->show_price = wcpa_get_option('show_price_in_order', true);
$quantity = $item->get_quantity();
if ($this->show_price == false) {// dont compare with === , $show_price will be 1 for true and 0 for false
$meta->value = $display_value = $this->order_meta_plain($wcpa_data, false,$quantity);
}
switch ($wcpa_data['type']) {
case 'text':
case 'date':
case 'number':
case 'time':
case 'datetime-local':
case 'header':
$out_display_value = $display_value;
break;
case 'textarea':
$out_display_value = nl2br($meta->value);
break;
case 'paragraph':
$out_display_value = do_shortcode(nl2br($meta->value));
break;
case 'color':
$out_display_value = '■' . $meta->value;
case 'select':
case 'checkbox-group':
case 'radio-group':
break;
// return $display_value; //str_replace(', ', '
', $meta->value);
case 'file':
$out_display_value = $this->display_meta_value_file($wcpa_data['value']);
break;
case 'image-group':
$out_display_value = $this->display_meta_value_image($wcpa_data);
break;
case 'color-group':
$out_display_value = $this->display_meta_value_colorgroup($wcpa_data);
break;
case 'placeselector':
if (!empty($wcpa_data['value']['formated'])) {
$display = $wcpa_data['value']['formated'] . '
';
if (!empty($wcpa_data['value']['splited']['street_number'])) {
$display .= __('Street address:', 'wcpa-text-domain') . ' ' . $wcpa_data['value']['splited']['street_number'] . ' ' . $wcpa_data['value']['splited']['route'] . '
';
}
if (!empty($wcpa_data['value']['splited']['locality'])) {
$display .= __('City:', 'wcpa-text-domain') . ' ' . $wcpa_data['value']['splited']['locality'] . '
';
}
if (!empty($wcpa_data['value']['splited']['administrative_area_level_1'])) {
$display .= __('State:', 'wcpa-text-domain') . ' ' . $wcpa_data['value']['splited']['administrative_area_level_1'] . '
';
}
if (!empty($wcpa_data['value']['splited']['postal_code'])) {
$display .= __('Zip code:', 'wcpa-text-domain') . ' ' . $wcpa_data['value']['splited']['postal_code'] . '
';
}
if (!empty($wcpa_data['value']['splited']['country'])) {
$display .= __('Country:', 'wcpa-text-domain') . ' ' . $wcpa_data['value']['splited']['country'] . '
';
}
if (isset($wcpa_data['value']['cords']['lat']) && !empty($wcpa_data['value']['cords']['lat'])) {
$display .= __('Latitude:', 'wcpa-text-domain') . ' ' . $wcpa_data['value']['cords']['lat'] . '
';
$display .= __('Longitude:', 'wcpa-text-domain') . ' ' . $wcpa_data['value']['cords']['lng'] . '
';
$display .= '' . __('View on map', 'wcpa-text-domain') . '
';
}
$out_display_value = $display;
break;
} else {
$out_display_value = $display_value;
break;
}
default:
$out_display_value = $display_value;
break;
}
} else {
$out_display_value = $display_value;
}
return apply_filters('wcpa_order_item_display_meta_value', $out_display_value,$display_value, $wcpa_data);
}
public function display_meta_value_file($value) {
$display = '';
if (isset($value['url'])) {
$display .= '';
if (in_array($value['type'], array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'))) {
$display .= '';
} else {
$display .= '
';
}
$display .= $value['file_name'] . '';
}
return $display;
}
public function display_meta_value_colorgroup($value) {
$style = array();
$display = '
';
$img_size_style = ((isset($value['form_data']->disp_size_img) && $value['form_data']->disp_size_img > 0) ? 'style="width:' . $value['form_data']->disp_size_img . 'px"' : '');
$display .= '';
$display .= $v['label'];
} else if ($v['i'] === 'other') {
$display .= '
'; $display .= __('Other:', 'wcpa-text-domain') . ' ' . $v['label']; } if ($this->show_price && $value['price'] && is_array($value['price'])) { if (isset($value['price'][$k]) && $value['price'][$k] !== FALSE) { $display .= '(' . wcpa_price($value['price'][$k]) . ')'; } } else { if ($this->show_price && $value['price'] !== FALSE) { $display .= ' (' . wcpa_price($value['price']) . ')'; } } } $display .= '