12.1 Xây dựng field title (ok)
Last updated
Was this helpful?
Last updated
Was this helpful?
C:\xampp\htdocs\test\wp-content\plugins\plugin-name\includes\class-wpf-utils_ct.php
<?php
class WPF_Utils_CT {
public static function get_wc_attributes($receate = FALSE) {
static $attributes = null;
if (is_null($attributes)) {
$attribute_taxonomies = wc_get_attribute_taxonomies();
if (!empty($attribute_taxonomies)) {
foreach ($attribute_taxonomies as $tax) {
$name = wc_attribute_taxonomy_name($tax->attribute_name);
$attributes[$name] = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
}
} else {
$attributes = array();
}
}
return $attributes;
}
public static function get_default_fields() {
static $labels = array();
if (empty($labels)) {
$labels = array(
'title' => __('Product Title', 'wpf'),
'sku' => __('SKU', 'wpf'),
'wpf_ct_cat' => __('Category', 'wpf'),
'wpf_ct_tag' => __('Tag', 'wpf'),
'price' => __('Price', 'wpf'),
'instock' => __('In Stock', 'wpf'),
'onsale' => __('On Sale', 'wpf'),
'submit' => __('Submit Button', 'wpf'),
);
}
return $labels;
}
public static function module_multi_text($id, array $data, array $languages, $key, $name, $input = 'text', $placeholder = false) {
?>
<div class="wpf_ct_back_active_module_row">
<?php if (!$placeholder): ?>
<div class="wpf_ct_back_active_module_label">
<label for="<?php echo $id ?>_<?php echo $key ?>"><?php echo $name; ?></label>
</div>
<?php endif; ?>
<?php self::module_language_tabs($id, $data, $languages, $key, $input, $placeholder); ?>
</div>
<?php
}
public static function module_language_tabs($id, array $data, array $languages, $key, $input = 'text', $placeholder = false, $as_array = false) {
?>
<?php if (!empty($languages)): ?>
<div class="wpf_ct_back_active_module_input">
<?php
$name = $as_array ? $id : '[' . $id . ']';
if ( $key ) {
$name .= '[' . $key . ']';
$values = isset( $data[ $key ] ) ? $data[ $key ] : array();
} else {
$values = isset( $data[ $id ] ) ? $data[ $id ] : array();
}
?>
<ul class="wpf_language_fields">
<?php foreach ($languages as $code => $lng ) :
$value = isset( $values[ $code ] ) ? $values[ $code ] : '';
?>
<li data-lng="wpf_lng_<?php echo $code ?>" <?php if (isset($lng['selected'])): ?>class="wpf_active_lng"<?php endif; ?>>
<?php
switch ($input) {
case 'text':
?>
<input id="wpf_<?php echo $id ?><?php if ($key): ?>_<?php echo $key ?><?php endif;?>"
<?php if ($placeholder): ?>placeholder="<?php echo $placeholder ?>" <?php endif;?> type="text"
class="wpf_towidth" name="<?php echo $name ?>[<?php echo $code ?>]"
<?php if ($value): ?>value="<?php esc_attr_e($value)?>" <?php endif;?> />
<?php
break;
}
?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php
}
}
?>