関数
Semantic::uscesCustomFieldInput( array $data, string $custom_field, string $position )
カスタムフィールドメタを表示する
パラメータ パラメータ
- $data
(配列) (必須)
- $custom_field
(文字列) (必須)
- $position
(文字列) (必須)
ファイル: src/Components/CustomFields/Templates/Semantic.php
public function uscesCustomFieldInput($data, $custom_field, $position) {
global $usces_essential_mark;
$label = 'custom_' . $custom_field;
$meta = usces_has_custom_field_meta($custom_field);
ob_start();
if (!empty($meta) && is_array($meta)) {
foreach ($meta as $key => $entry) {
if ($custom_field === 'order' || $entry['position'] === $position) {
$name = $entry['name'];
$means = (int)$entry['means'];
$essential = (int)$entry['essential'];
$value = '';
if (is_array($entry['value'])) {
foreach ($entry['value'] as $k => $v) {
$value .= $v . "\n";
}
}
$value = usces_change_line_break($value);
$e = '';
if ($essential === 1) {
$e = isset($usces_essential_mark[$key])
? usces_get_essential_mark($key)
: '<em>' . __('*', 'usces') . '</em>';
}
/**
* Mirrored Welcart filter
*
* @ignore
*/
$heading = $e . esc_html($name) . apply_filters(
'usces_filter_custom_field_input_label',
null,
$key,
$entry
);
switch ($means) {
case 0: // シングルセレクト
case 1: // マルチセレクト NOTE: multi-select isnt an option for custom fields
$selects = explode("\n", $value);
?>
<div class="field">
<label><?php echo $heading ?></label>
<select
v-model="customFields.<?php echo esc_attr($key) ?>.value"
name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
class="ui dropdown"
>
<option value="#NONE#"><?php echo esc_html__('Choose', 'usces') ?></option>
<?php
foreach ($selects as $v) :
$selected = (isset($data[$label][$key]) && $data[$label][$key] == $v)
? ' selected'
: '';
?>
<option value="<?php echo esc_attr($v) ?>" <?php echo esc_attr($selected) ?>>
<?php echo esc_html($v) ?>
</option>
<?php
endforeach;
?>
</select>
</div>
<!-- <div v-cloak v-if="errorMessages.<?php // echo esc_attr($key) ?>" class="error_message">
<?php // echo '{{ errorMessages.' . esc_attr($key) . '}}' ?>
</div> -->
<?php
break;
case 2: // テキスト
?>
<div class="field">
<label><?php echo $heading ?></label>
<input
type="text"
v-model="customFields.<?php echo esc_attr($key) ?>.value"
name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
>
</div>
<?php
break;
case 3: // ラジオボタン
?>
<div class="grouped fields customkey_<?php echo esc_attr($key) ?>">
<label><?php echo $heading ?></label>
<?php
$selects = explode("\n", $value);
foreach ($selects as $v) :
$checked = (isset($data[$label][$key]) && $data[$label][$key] == $v)
? ' checked'
: '';
?>
<div class="field">
<div class="ui radio checkbox">
<input
type="radio"
v-model="customFields.<?php echo esc_attr($key) ?>.value"
name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
id="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>][<?php echo esc_attr($v) ?>]"
value="<?php echo esc_attr($v) ?>"<?php echo esc_attr($checked) ?>
>
<label class="iopt_label"><?php echo esc_html($v) ?></label>
</div>
</div>
<?php
endforeach;
?>
</div>
<?php
break;
case 4: // チェックボックス
$selects = explode("\n", $value);
?>
<div class="grouped fields customkey_<?php echo esc_attr($key) ?>">
<label><?php echo $heading ?></label>
<?php
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'
: '';
}
?>
<div class="field">
<div class="ui checkbox">
<input
type="checkbox"
v-model="customFields.<?php echo esc_attr($key) ?>.value[<?php echo '\'' . esc_attr($v) . '\'' ?>]"
name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>][<?php echo esc_attr($v) ?>]"
value="<?php echo esc_attr($v) ?>"<?php echo esc_attr($checked) ?>
>
<label><?php echo esc_html($v) ?></label>
</div>
</div>
<?php
endforeach;
?>
</div>
<?php
break;
case 5: // Text-area
?>
<div class="field">
<label><?php echo $heading ?></label>
<textarea
v-model="customFields.<?php echo esc_attr($key) ?>.value"
name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
></textarea>
</div>
<?php
break;
}
}
}
}
$html = ob_get_clean();
if (!empty($html)) {
$html = '<div class="ui form aap" id="' . esc_attr('custom_' . $custom_field) . '">' . $html . '</div>';
}
/**
* 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);
}