関数
Welcart::uscesCustomFieldInput( array $data, string $custom_field, string $position )
カスタムフィールドメタを表示する
パラメータ パラメータ
- $data
(配列) (必須)
- $custom_field
(文字列) (必須)
- $position
(文字列) (必須)
ファイル: src/Components/CustomFields/Templates/Welcart.php
public function uscesCustomFieldInput($data, $custom_field, $position) {
$label = 'custom_' . $custom_field;
$meta = usces_has_custom_field_meta($custom_field);
$html = '';
if (!empty($meta) && is_array($meta)) {
foreach ($meta as $key => $entry) {
if ($custom_field === 'order' || $entry['position'] === $position) {
$name = $entry['name'];
$means = $entry['means'];
$essential = $entry['essential'];
$value = '';
if (is_array($entry['value'])) {
foreach ($entry['value'] as $k => $v) {
$value .= $v . "\n";
}
}
$value = usces_change_line_break($value);
$e = ($essential == 1) ? '<em>' . __('*', 'usces') . '</em>' : '';
/**
* Mirrored Welcart filter
*
* @ignore
*/
$customlabel = apply_filters('usces_filter_custom_field_input_label', null, $key, $entry);
$html .= '
<tr class="customkey_' . $key . '">
<th scope="row">' . $e . esc_html($name) . $customlabel . '</th>';
/**
* Mirrored Welcart filter
*
* @ignore
*/
$html .= apply_filters('usces_filter_custom_field_input_td', '<td colspan="2">', $key, $entry);
switch ($means) {
case 0: // シングルセレクト
case 1: // マルチセレクト NOTE: multi-select isnt an option for custom fields
$selects = explode("\n", $value);
$multiple = ($means == 0) ? '' : ' multiple';
$multiple_array = ($means == 0) ? '' : '[]';
$html .= '<select
v-model="customFields[\'' . esc_attr($key) . '\'].value"
name="' . $label . '[' . esc_attr($key) . ']' . $multiple_array . '"
class="iopt_select"' . $multiple . '
>';
if ($essential == 1) {
$html .= '
<option value="#NONE#">' . __('Choose', 'usces') . '</option>';
}
foreach ($selects as $v) {
$selected = (isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' selected' : '';
$html .= '
<option value="' . esc_attr($v) . '"' . $selected . '>' . esc_html($v) . '</option>';
}
$html .= '
</select>';
break;
case 2: // テキスト
$html .= '<input
type="text"
v-model="customFields[\'' . esc_attr($key) . '\'].value"
name="' . $label . '[' . esc_attr($key) . ']"
/>';
break;
case 3: // ラジオボタン
$selects = explode("\n", $value);
foreach ($selects as $v) {
$checked = (isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' checked' : '';
$html .= '<label for="' . $label . '[' . esc_attr($key) . '][' . esc_attr($v) . ']" class="iopt_label">';
$html .= '<input
type="radio"
v-model="customFields[\'' . esc_attr($key) . '\'].value"
name="' . $label . '[' . esc_attr($key) . ']"
id="' . $label . '[' . esc_attr($key) . '][' . esc_attr($v) . ']"
value="' . esc_attr($v) . '"' . $checked . '
>';
$html .= esc_html($v) . '</label>';
}
break;
case 4: // チェックボックス
$selects = explode("\n", $value);
foreach ($selects as $v) {
if (isset($data[$label][$key]) && is_array($data[$label][$key])) {
$checked = (isset($data[$label][$key]) && array_key_exists($v, $data[$label][$key])) ? ' checked' : '';
} else {
$checked = (isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' checked' : '';
}
$html .= '<label for="' . $label . '[' . esc_attr($key) . '][' . esc_attr($v) . ']" class="iopt_label">';
$html .= '<input
type="checkbox"
v-model="customFields[\'' . esc_attr($key) . '\'].value[\'' . esc_attr($v) . '\']"
name="' . $label . '[' . esc_attr($key) . '][' . esc_attr($v) . ']"
id="' . $label . '[' . esc_attr($key) . '][' . esc_attr($v) . ']"
value="' . esc_attr($v) . '"' . $checked . '
>';
$html .= esc_html($v) . '</label>';
}
break;
case 5: // Text-area
$html .= '<textarea
v-model="customFields[\'' . esc_attr($key) . '\'].value"
name="' . $label . '[' . esc_attr($key) . ']"
class="iopt_textarea"
></textarea>';
break;
}
/**
* Mirrored Welcart filter
*
* @ignore
*/
$html .= apply_filters('usces_filter_custom_field_input_value', null, $key, $entry) . '</td>';
$html .= '
</tr>';
}
}
}
if (!empty($html)) {
$html = '<table class="customer_form" id="' . esc_attr('custom_' . $custom_field) . '">' . $html . '</table>';
}
/**
* Filters the custom fields HTML shown on the Quickpay page
*
* @param string $html
* @param array $data
* @param string $custom_field
* @param string $position
*/
$html = apply_filters('wcexaap_filter_custom_field_input', $html, $data, $custom_field, $position);
echo stripslashes($html);
}