79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
if ( ! class_exists( 'GFForms' ) ) {
|
|
die();
|
|
}
|
|
|
|
class Wiaas_Field_Order_Supplier_Select extends GF_Field_Select {
|
|
|
|
public $type = 'wiaas_order_supplier';
|
|
|
|
public function get_form_editor_field_title() {
|
|
return esc_attr__( 'Supplier Select', 'wiaas' );
|
|
}
|
|
|
|
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
|
return $this->_get_selected_supplier_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_supplier_display_name($value);
|
|
}
|
|
|
|
|
|
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
|
return $this->_get_selected_supplier_display_name($value);
|
|
}
|
|
|
|
|
|
/**
|
|
* Adds bundles as choices
|
|
*/
|
|
public function post_convert_field() {
|
|
$this->choices = array();
|
|
|
|
if ( ! $this->is_form_editor() ) {
|
|
$this->choices = $this->_get_suppliers_as_choices();
|
|
}
|
|
}
|
|
|
|
|
|
private function _get_selected_supplier_display_name($value) {
|
|
|
|
list ($order_id, $supplier_id) = explode('|', $value);
|
|
|
|
if (! empty($order_id) && ! empty($supplier_id) && $order = wc_get_order($order_id)) {
|
|
|
|
return wiaas_get_organization_name($supplier_id);
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
|
|
private function _get_suppliers_as_choices() {
|
|
|
|
$choices = array();
|
|
|
|
$order_id = absint(rgget('order_id'));
|
|
|
|
if (! empty ($order_id) && $order = wc_get_order($order_id)) {
|
|
|
|
$suppliers = wiaas_get_order_suppliers($order);
|
|
|
|
foreach ($suppliers as $supplier_id => $supplier_name) {
|
|
|
|
$choices[] = array(
|
|
'value' => $order_id . '|' . $supplier_id,
|
|
'text' => $supplier_name
|
|
);
|
|
}
|
|
}
|
|
|
|
return $choices;
|
|
}
|
|
}
|
|
|
|
GF_Fields::register( new Wiaas_Field_Order_Supplier_Select() );
|