110 lines
2.4 KiB
PHP
110 lines
2.4 KiB
PHP
<?php
|
|
|
|
if ( ! class_exists( 'GFForms' ) ) {
|
|
die();
|
|
}
|
|
|
|
class Wiaas_Field_Order_Bundle_Select extends GF_Field_Select {
|
|
|
|
|
|
public $type = 'wiaas_order_bundle';
|
|
|
|
|
|
public function get_form_editor_field_title() {
|
|
return esc_attr__( 'Bundle Select', 'wiaas' );
|
|
}
|
|
|
|
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
|
return $this->get_selected_bundle_display_name($value);
|
|
}
|
|
|
|
|
|
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
|
return $this->get_selected_bundle_display_name($value);
|
|
}
|
|
|
|
|
|
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
|
return $this->get_selected_bundle_display_name($value);
|
|
}
|
|
|
|
public function get_field_input( $form, $value = '', $entry = null ) {
|
|
|
|
$this->choices = array();
|
|
|
|
$order_id = null;
|
|
|
|
if (! empty($entry)) {
|
|
|
|
$order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order' ) )[0];
|
|
|
|
$order_id = ! empty($order_field) ? $entry[$order_field->id] : null;
|
|
|
|
} else if( ! empty($value)) {
|
|
|
|
list ($order_id, $item_id) = explode('|', $value);
|
|
}
|
|
|
|
if (! empty($order_id)) {
|
|
|
|
$this->choices = $this->get_selected_bundle_display_name($order_id);
|
|
}
|
|
|
|
return parent::get_field_input( $form, $value, $entry );
|
|
}
|
|
|
|
|
|
/**
|
|
* Adds bundles as choices
|
|
*/
|
|
public function post_convert_field() {
|
|
|
|
if ($this->is_form_editor()) {
|
|
|
|
$this->choices = array();
|
|
}
|
|
|
|
if ( ! $this->is_form_editor() && ! empty( rgget('order_id') )) {
|
|
$this->choices = $this->get_bundles_as_choices(absint(rgget('order_id')));
|
|
}
|
|
}
|
|
|
|
|
|
public function get_selected_bundle_display_name($value) {
|
|
|
|
list ($order_id, $item_id) = explode('|', $value);
|
|
|
|
if (! empty($order_id) && ! empty($item_id) && $order = wc_get_order($order_id)) {
|
|
|
|
$item = $order->get_item($item_id);
|
|
|
|
return $item->get_name();
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
|
|
public function get_bundles_as_choices($order_id) {
|
|
|
|
$choices = array();
|
|
|
|
if (! empty ($order_id) && $order = wc_get_order($order_id)) {
|
|
|
|
$standard_bundle_items = wiaas_get_order_standard_bundle_items($order);
|
|
|
|
foreach ($standard_bundle_items as $item) {
|
|
|
|
$choices[] = array(
|
|
'value' => $order_id . '|' . $item->get_id(),
|
|
'text' => $item->get_name()
|
|
);
|
|
}
|
|
}
|
|
|
|
return $choices;
|
|
}
|
|
}
|
|
|
|
GF_Fields::register( new Wiaas_Field_Order_Bundle_Select() );
|