Initial Commit N° : 001 - V.4.3.3
This commit is contained in:
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
if (NASA_WOO_ACTIVED && class_exists('YITH_WCBR')) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_brands_widget');
|
||||
|
||||
function elessi_product_brands_widget() {
|
||||
register_widget('Elessi_Product_Brands_Widget');
|
||||
}
|
||||
|
||||
class Elessi_Product_Brands_Widget extends WC_Widget {
|
||||
|
||||
const TAX_NAME = 'yith_product_brand';
|
||||
|
||||
/**
|
||||
* Category ancestors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $brand_ancestors;
|
||||
|
||||
/**
|
||||
* Current Category
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $current_brand;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_product_brands';
|
||||
$this->widget_description = __('Display yith product brands with Accordion.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_product_brands';
|
||||
$this->widget_name = 'Nasa - Yith Product Brands';
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __('Product Brands', 'elessi-theme'),
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
'count' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 0,
|
||||
'label' => __('Show product counts', 'elessi-theme')
|
||||
),
|
||||
'accordion' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('Show as Accordion', 'elessi-theme')
|
||||
),
|
||||
'show_items' => array(
|
||||
'type' => 'text',
|
||||
'std' => 'All',
|
||||
'label' => __('Show default numbers items', 'elessi-theme')
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a particular instance of a widget.
|
||||
*
|
||||
* @see WP_Widget->update
|
||||
*
|
||||
* @param array $new_instance
|
||||
* @param array $old_instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function update($new_instance, $old_instance) {
|
||||
$this->nasa_settings($new_instance);
|
||||
|
||||
return parent::update($new_instance, $old_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* form function.
|
||||
*
|
||||
* @see WP_Widget->form
|
||||
* @param array $instance
|
||||
*/
|
||||
public function form($instance) {
|
||||
$this->nasa_settings($instance);
|
||||
|
||||
if (empty($this->settings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->settings as $key => $setting) {
|
||||
$value = isset($instance[$key]) ? $instance[$key] : $setting['std'];
|
||||
$_id = $this->get_field_id($key);
|
||||
$_name = $this->get_field_name($key);
|
||||
|
||||
switch ($setting['type']) {
|
||||
|
||||
case 'text' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="text" value="<?php echo esc_attr($value); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'number' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="number" step="<?php echo esc_attr($setting['step']); ?>" min="<?php echo esc_attr($setting['min']); ?>" max="<?php echo esc_attr($setting['max']); ?>" value="<?php echo esc_attr($value); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'select' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<select class="widefat" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>">
|
||||
<?php foreach ($setting['options'] as $o_key => $o_value): ?>
|
||||
<option value="<?php echo esc_attr($o_key); ?>" <?php selected($o_key, $value); ?>><?php echo esc_html($o_value); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'checkbox' :
|
||||
?>
|
||||
<p>
|
||||
<input id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="checkbox" value="1" <?php checked($value, 1); ?> />
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
// Button chosen icon font
|
||||
case 'icons':
|
||||
echo ($this->getTemplateAdminIcon($_name, $_id, $setting['label'], $value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTemplateAdminIcon($_name, $_id, $label, $value) {
|
||||
$content = '<p>';
|
||||
$content .= '<a class="nasa-chosen-icon" data-fill="' . esc_attr($_id) . '">' . esc_html__('Click select icon for ', 'elessi-theme') . '</a>';
|
||||
$content .= '<span id="ico-' . esc_attr($_id) . '">';
|
||||
|
||||
if ($value):
|
||||
$content .= '<i class="' . esc_attr($value) . '"></i>';
|
||||
$content .= '<a href="javascript:void(0);" class="nasa-remove-icon" data-id="' . esc_attr($_id) . '" rel="nofollow">';
|
||||
$content .= '<i class="fa fa-remove"></i>';
|
||||
$content .= '</a>';
|
||||
endif;
|
||||
|
||||
$content .= '</span>';
|
||||
$content .= '<label for="' . $_id . '">' . $label . '</label><br />';
|
||||
$content .= '<input class="widefat" id="' . esc_attr($_id) . '" name="' . $_name . '" type="hidden" readonly="true" value="' . esc_attr($value) . '" />';
|
||||
$content .= '</p>';
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init settings after post types are registered.
|
||||
*/
|
||||
public function nasa_settings($instance) {
|
||||
// Default setting color
|
||||
if (empty($instance)) {
|
||||
if ($default = get_option('widget_' . $this->widget_id, true)) {
|
||||
foreach ($default as $v) {
|
||||
$instance = $v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$top_level = get_terms(apply_filters('woocommerce_product_attribute_terms', array(
|
||||
'taxonomy' => self::TAX_NAME,
|
||||
'hierarchical' => true,
|
||||
'hide_empty' => false
|
||||
)));
|
||||
|
||||
if ($top_level) {
|
||||
foreach ($top_level as $v) {
|
||||
// Change settings
|
||||
$this->settings['brand_' . $v->slug] = array(
|
||||
'type' => 'icons',
|
||||
'std' => isset($instance['brand_' . $v->slug]) ? $instance['brand_' . $v->slug] : '',
|
||||
'label' => '<b>' . $v->name . '</b>'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
global $wp_query, $post;
|
||||
$show_items = isset($instance['show_items']) ? (int) $instance['show_items'] : 0;
|
||||
|
||||
$a = isset($instance['accordion']) ? $instance['accordion'] : $this->settings['accordion']['std'];
|
||||
$c = isset($instance['count']) ? $instance['count'] : $this->settings['count']['std'];
|
||||
$h = isset($instance['hierarchical']) ? $instance['hierarchical'] : 1;
|
||||
$o = isset($instance['orderby']) ? $instance['orderby'] : 'name';
|
||||
$list_args = array('show_count' => $c, 'hierarchical' => $h, 'taxonomy' => self::TAX_NAME, 'hide_empty' => false);
|
||||
|
||||
// Menu Order
|
||||
$list_args['menu_order'] = false;
|
||||
if ($o == 'order') {
|
||||
$list_args['menu_order'] = 'asc';
|
||||
} else {
|
||||
$list_args['orderby'] = 'title';
|
||||
}
|
||||
|
||||
// Setup Current Category
|
||||
$this->current_brand = false;
|
||||
$this->brand_ancestors = array();
|
||||
|
||||
if (is_tax(self::TAX_NAME)) {
|
||||
$this->current_brand = $wp_query->queried_object;
|
||||
$this->brand_ancestors = get_ancestors($this->current_brand->term_id, self::TAX_NAME);
|
||||
} elseif (is_singular('product')) {
|
||||
$product_brand = wc_get_product_terms($post->ID, self::TAX_NAME, array('orderby' => 'parent'));
|
||||
|
||||
if ($product_brand) {
|
||||
$this->current_brand = end($product_brand);
|
||||
$this->brand_ancestors = get_ancestors($this->current_brand->term_id, self::TAX_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
$menu_cat = new Elessi_Product_Brand_List_Walker();
|
||||
$menu_cat->setIcons($instance);
|
||||
$menu_cat->setShowDefault($show_items);
|
||||
$list_args['walker'] = $menu_cat;
|
||||
$list_args['title_li'] = '';
|
||||
$list_args['pad_counts'] = 1;
|
||||
$list_args['show_option_none'] = esc_html__('No product categories exist.', 'elessi-theme');
|
||||
$list_args['current_brand'] = $this->current_brand ? $this->current_brand->term_id : '';
|
||||
$list_args['current_brand_ancestors'] = $this->brand_ancestors;
|
||||
$accordion = $a ? ' nasa-accordion' : ' ns-ctree';
|
||||
|
||||
echo '<ul class="nasa-root-cat nasa-root-tax product-categories' . $accordion . '">';
|
||||
wp_list_categories(apply_filters('woocommerce_yith_product_brands_widget_args', $list_args));
|
||||
|
||||
if ($show_items && ($menu_cat->getTotalRoot() > $show_items)) {
|
||||
echo '<li class="nasa_show_manual"><a data-show="1" class="nasa-show" href="javascript:void(0);" data-text="' . esc_attr__('- Show less', 'elessi-theme') . '" rel="nofollow">' . esc_html__('+ Show more', 'elessi-theme') . '</a></li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
$this->widget_end($args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!class_exists('WC_Product_Cat_List_Walker')) {
|
||||
require_once WC()->plugin_path() . '/includes/walkers/class-product-cat-list-walker.php';
|
||||
}
|
||||
|
||||
class Elessi_Product_Brand_List_Walker extends WC_Product_Cat_List_Walker {
|
||||
|
||||
protected $_icons = array();
|
||||
protected $_k = 0;
|
||||
protected $_show_default = 0;
|
||||
protected $_filter_type = 'only';
|
||||
protected $_class_ajax = 'nasa-filter-by-tax';
|
||||
|
||||
public function __construct() {
|
||||
$this->tree_type = Elessi_Product_Brands_Widget::TAX_NAME;
|
||||
}
|
||||
|
||||
public function setIcons($instance) {
|
||||
$this->_icons = $instance;
|
||||
}
|
||||
|
||||
public function setFilterType($type = 'only') {
|
||||
$this->_filter_type = $type == 'or' ? 'or' : 'only';
|
||||
$this->_class_ajax = $this->_filter_type == 'only' ? 'nasa-filter-by-cat' : 'nasa-filter-by-brand';
|
||||
}
|
||||
|
||||
public function setShowDefault($show) {
|
||||
$this->_show_default = (int) $show;
|
||||
}
|
||||
|
||||
public function getTotalRoot() {
|
||||
return $this->_k;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::start_el()
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param int $depth Depth of category in reference to parents.
|
||||
* @param integer $current_object_id
|
||||
*/
|
||||
public function start_el(&$output, $brand, $depth = 0, $args = array(), $current_object_id = 0) {
|
||||
$output .= '<li class="cat-item cat-item-' . $brand->term_id . ' cat-item-' . $brand->slug;
|
||||
$nasa_active = $accordion = $icon = '';
|
||||
if ($depth == 0) {
|
||||
$output .= ' root-item';
|
||||
|
||||
if ($this->_show_default && ($this->_k >= $this->_show_default)) {
|
||||
$output .= ' nasa-show-less';
|
||||
}
|
||||
|
||||
$this->_k++;
|
||||
}
|
||||
|
||||
if (isset($this->_icons['brand_' . $brand->slug]) && trim($this->_icons['brand_' . $brand->slug]) != '') {
|
||||
$icon = '<i class="nasa-icon nasa-brand-icon ' . $this->_icons['brand_' . $brand->slug] . '"></i> ';
|
||||
}
|
||||
|
||||
if ($args['current_brand'] == $brand->term_id) {
|
||||
$output .= ' current-cat active';
|
||||
$nasa_active = ' nasa-active';
|
||||
}
|
||||
|
||||
if ($args['has_children'] && $args['hierarchical']) {
|
||||
$output .= ' cat-parent li_accordion';
|
||||
$accordion = '<a href="javascript:void(0);" class="accordion" rel="nofollow"></a>';
|
||||
}
|
||||
|
||||
if ($args['current_brand_ancestors'] && $args['current_brand'] && in_array($brand->term_id, $args['current_brand_ancestors'])) {
|
||||
$output .= ' current-cat-parent active';
|
||||
}
|
||||
|
||||
$output .= '">' . $accordion;
|
||||
|
||||
$href = get_term_link($brand, $this->tree_type);
|
||||
$output .= '<a ' .
|
||||
'href="' . esc_url($href) . '" ' .
|
||||
'title="' . esc_attr($brand->name) . '" ' .
|
||||
'data-id="' . esc_attr((int) $brand->term_id) . '" ' .
|
||||
'data-slug="' . esc_attr($brand->slug) . '" ' .
|
||||
'class="nasa-filter-item ' . $this->_class_ajax . $nasa_active . '" ' .
|
||||
'data-taxonomy="' . $this->tree_type . '">' .
|
||||
$icon . $brand->name;
|
||||
$output .= $args['show_count'] ? ' <span class="count">' . $brand->count . '</span>' : '';
|
||||
$output .= '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,587 @@
|
||||
<?php
|
||||
/**
|
||||
* Exit if accessed directly
|
||||
*/
|
||||
defined('ABSPATH') or die();
|
||||
|
||||
/**
|
||||
* If WooCommerce Active
|
||||
*/
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_categories_widget');
|
||||
function elessi_product_categories_widget() {
|
||||
register_widget('Elessi_Product_Categories_Widget');
|
||||
}
|
||||
|
||||
class Elessi_Product_Categories_Widget extends WC_Widget {
|
||||
|
||||
/**
|
||||
* Category ancestors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $cat_ancestors;
|
||||
|
||||
/**
|
||||
* Current Category
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $current_cat;
|
||||
|
||||
/**
|
||||
* Icons Support
|
||||
*/
|
||||
protected $_icons_sp;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
global $wp_version, $nasa_opt;
|
||||
|
||||
$this->widget_cssclass = 'woocommerce widget_product_categories';
|
||||
$this->widget_description = __('Display product categories with Accordion.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_product_categories';
|
||||
$this->widget_name = 'Nasa - Product Categories';
|
||||
|
||||
$this->_icons_sp = true;
|
||||
|
||||
if (
|
||||
isset($wp_version) &&
|
||||
version_compare($wp_version, '5.8', ">=") &&
|
||||
isset($nasa_opt['block_editor_widgets']) &&
|
||||
$nasa_opt['block_editor_widgets']
|
||||
) {
|
||||
$this->_icons_sp = apply_filters('nasa_block_editor_wg_cat_icons_sp', false);
|
||||
}
|
||||
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => 'Product Categories',
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
'orderby' => array(
|
||||
'type' => 'select',
|
||||
'std' => 'name',
|
||||
'label' => __('Order by', 'elessi-theme'),
|
||||
'options' => array(
|
||||
'order' => __('Category Order', 'elessi-theme'),
|
||||
'name' => __('Name', 'elessi-theme')
|
||||
)
|
||||
),
|
||||
'count' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 0,
|
||||
'label' => __('Show product counts', 'elessi-theme')
|
||||
),
|
||||
'hierarchical' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('Show hierarchy', 'elessi-theme')
|
||||
),
|
||||
'show_children_only' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 0,
|
||||
'label' => __('Only show children of the current category', 'elessi-theme')
|
||||
),
|
||||
'hide_empty' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 0,
|
||||
'label' => __('Hide empty categories', 'elessi-theme'),
|
||||
),
|
||||
'accordion' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('Show as Accordion', 'elessi-theme')
|
||||
),
|
||||
'show_items' => array(
|
||||
'type' => 'text',
|
||||
'std' => 'All',
|
||||
'label' => __('Show default numbers items', 'elessi-theme')
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a particular instance of a widget.
|
||||
*
|
||||
* @see WP_Widget->update
|
||||
*
|
||||
* @param array $new_instance
|
||||
* @param array $old_instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function update($new_instance, $old_instance) {
|
||||
if ($this->_icons_sp) {
|
||||
$this->nasa_settings($new_instance);
|
||||
}
|
||||
|
||||
return parent::update($new_instance, $old_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* form function.
|
||||
*
|
||||
* @see WP_Widget->form
|
||||
* @param array $instance
|
||||
*/
|
||||
public function form($instance) {
|
||||
if ($this->_icons_sp) {
|
||||
$this->nasa_settings($instance);
|
||||
}
|
||||
|
||||
if (empty($this->settings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->settings as $key => $setting) {
|
||||
$value = isset($instance[$key]) ? $instance[$key] : (isset($setting['std']) ? $setting['std'] : '');
|
||||
$_id = $this->get_field_id($key);
|
||||
$_name = $this->get_field_name($key);
|
||||
|
||||
switch ($setting['type']) {
|
||||
|
||||
case 'text' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="text" value="<?php echo esc_attr($value); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'number' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="number" step="<?php echo esc_attr($setting['step']); ?>" min="<?php echo esc_attr($setting['min']); ?>" max="<?php echo esc_attr($setting['max']); ?>" value="<?php echo esc_attr($value); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'select' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<select class="widefat" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>">
|
||||
<?php foreach ($setting['options'] as $o_key => $o_value): ?>
|
||||
<option value="<?php echo esc_attr($o_key); ?>" <?php selected($o_key, $value); ?>><?php echo esc_html($o_value); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'checkbox' :
|
||||
?>
|
||||
<p>
|
||||
<input id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="checkbox" value="1" <?php checked($value, 1); ?> />
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'toggle-show-icon' :
|
||||
?>
|
||||
<p>
|
||||
<a class="toggle-choose-icon-btn" href="javascript:void(0);" rel="nofollow">
|
||||
<?php echo esc_html__('Add icons for categories.', 'elessi-theme'); ?>
|
||||
</a>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
// Button chosen icon font
|
||||
case 'icons':
|
||||
echo $this->get_template_admin_icon($_name, $_id, $setting['label'], $value);
|
||||
break;
|
||||
|
||||
default :
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Icons
|
||||
*
|
||||
* @param type $_name
|
||||
* @param type $_id
|
||||
* @param type $label
|
||||
* @param type $value
|
||||
* @return string
|
||||
*/
|
||||
public function get_template_admin_icon($_name, $_id, $label, $value) {
|
||||
$content = '<p class="toggle-choose-icon hidden-tag">';
|
||||
$content .= '<a class="nasa-chosen-icon" data-fill="' . esc_attr($_id) . '">' . esc_html__('Click select icon for ', 'elessi-theme') . '</a>';
|
||||
$content .= '<span id="ico-' . esc_attr($_id) . '">';
|
||||
if ($value):
|
||||
$content .= '<i class="' . esc_attr($value) . '"></i>';
|
||||
$content .= '<a href="javascript:void(0);" class="nasa-remove-icon" data-id="' . esc_attr($_id) . '" rel="nofollow">';
|
||||
$content .= '<i class="fa fa-remove"></i>';
|
||||
$content .= '</a>';
|
||||
endif;
|
||||
$content .= '</span>';
|
||||
$content .= '<label for="' . $_id . '">' . $label . '</label><br />';
|
||||
$content .= '<input class="widefat" id="' . esc_attr($_id) . '" name="' . $_name . '" type="hidden" readonly="true" value="' . esc_attr($value) . '" />';
|
||||
$content .= '</p>';
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init settings after post types are registered.
|
||||
*/
|
||||
public function nasa_settings($instance) {
|
||||
// Default settings
|
||||
if (empty($instance)) {
|
||||
$default = get_option('widget_' . $this->widget_id, true);
|
||||
if ($default) {
|
||||
foreach ($default as $value) {
|
||||
$instance = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'taxonomy' => 'product_cat',
|
||||
'hierarchical' => true,
|
||||
'hide_empty' => false
|
||||
);
|
||||
|
||||
$top = apply_filters('nasa_admin_top_level_set_icon', true);
|
||||
if ($top) {
|
||||
$args['parent'] = 0;
|
||||
}
|
||||
|
||||
$cats = get_terms(apply_filters('woocommerce_product_attribute_terms', $args));
|
||||
|
||||
if ($cats) {
|
||||
$this->settings['toggle'] = array(
|
||||
'type' => 'toggle-show-icon',
|
||||
'std' => ''
|
||||
);
|
||||
|
||||
foreach ($cats as $cat) {
|
||||
// Change settings
|
||||
$this->settings['cat_' . $cat->slug] = array(
|
||||
'type' => 'icons',
|
||||
'std' => isset($instance['cat_' . $cat->slug]) ? $instance['cat_' . $cat->slug] : '',
|
||||
'label' => '<b>' . $cat->name . '</b>'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
global $wp_query, $post, $nasa_opt;
|
||||
|
||||
$accordion = isset($instance['accordion']) ? $instance['accordion'] : $this->settings['accordion']['std'];
|
||||
$count = isset($instance['count']) ? $instance['count'] : $this->settings['count']['std'];
|
||||
$hierarchical = isset($instance['hierarchical']) ? $instance['hierarchical'] : $this->settings['hierarchical']['std'];
|
||||
|
||||
$orderby = isset($instance['orderby']) ? $instance['orderby'] : $this->settings['orderby']['std'];
|
||||
$hide_empty = isset($instance['hide_empty']) ? $instance['hide_empty'] : $this->settings['hide_empty']['std'];
|
||||
$show_items = isset($instance['show_items']) ? (int) $instance['show_items'] : 0;
|
||||
|
||||
$show_children_only = isset($instance['show_children_only']) && $instance['show_children_only'] == '1' ? true : false;
|
||||
|
||||
$get_sidebar = false;
|
||||
$is_product = is_singular('product');
|
||||
|
||||
if (!$is_product) {
|
||||
$get_sidebar = isset($nasa_opt['category_sidebar']) ? $nasa_opt['category_sidebar'] : 'top';
|
||||
$get_sidebar = isset($_GET['sidebar']) ? $_GET['sidebar'] : $get_sidebar;
|
||||
$get_sidebar = in_array($get_sidebar, array('left', 'right', 'left-classic', 'right-classic', 'top-2', 'top-3')) ? $get_sidebar : 'top';
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all items
|
||||
*/
|
||||
$list_args = array(
|
||||
'show_count' => $count,
|
||||
'hierarchical' => $hierarchical,
|
||||
'taxonomy' => 'product_cat',
|
||||
'hide_empty' => $hide_empty
|
||||
);
|
||||
|
||||
// Menu Order
|
||||
$list_args['menu_order'] = false;
|
||||
if ($orderby === 'order') {
|
||||
$list_args['orderby'] = 'meta_value_num';
|
||||
$list_args['meta_key'] = 'order';
|
||||
} else {
|
||||
$list_args['orderby'] = 'title';
|
||||
}
|
||||
|
||||
// Setup Current Category
|
||||
$this->current_cat = false;
|
||||
$this->cat_ancestors = array();
|
||||
$root_id = 0;
|
||||
|
||||
if (is_tax('product_cat')) {
|
||||
$this->current_cat = $wp_query->queried_object;
|
||||
$this->cat_ancestors = get_ancestors($this->current_cat->term_id, 'product_cat');
|
||||
}
|
||||
|
||||
elseif ($is_product) {
|
||||
$terms = wc_get_product_terms(
|
||||
$post->ID,
|
||||
'product_cat',
|
||||
apply_filters(
|
||||
'woocommerce_product_categories_widget_product_terms_args',
|
||||
array(
|
||||
'orderby' => 'parent',
|
||||
'order' => 'DESC',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ($terms) {
|
||||
$main_term = apply_filters('woocommerce_product_categories_widget_main_term', $terms[0], $terms);
|
||||
$this->current_cat = $main_term;
|
||||
$this->cat_ancestors = get_ancestors($main_term->term_id, 'product_cat');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only Show Children
|
||||
*/
|
||||
if ($show_children_only && $this->current_cat) {
|
||||
if ($hierarchical) {
|
||||
$include = array_merge(
|
||||
$this->cat_ancestors,
|
||||
array($this->current_cat->term_id),
|
||||
get_terms(
|
||||
'product_cat',
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
'parent' => 0,
|
||||
'hierarchical' => true,
|
||||
'hide_empty' => false,
|
||||
)
|
||||
),
|
||||
get_terms(
|
||||
'product_cat',
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
'parent' => $this->current_cat->term_id,
|
||||
'hierarchical' => true,
|
||||
'hide_empty' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Gather siblings of ancestors.
|
||||
if ($this->cat_ancestors) {
|
||||
foreach ($this->cat_ancestors as $ancestor) {
|
||||
$include = array_merge(
|
||||
$include,
|
||||
get_terms(
|
||||
'product_cat',
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
'parent' => $ancestor,
|
||||
'hierarchical' => false,
|
||||
'hide_empty' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Direct children.
|
||||
$include = get_terms(
|
||||
'product_cat',
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
'parent' => $this->current_cat->term_id,
|
||||
'hierarchical' => true,
|
||||
'hide_empty' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$list_args['include'] = implode(',', $include);
|
||||
|
||||
if (empty($include)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
elseif ((isset($nasa_opt['disable_top_level_cat']) && $nasa_opt['disable_top_level_cat'])) {
|
||||
$root_id = $this->cat_ancestors ? end($this->cat_ancestors) :
|
||||
($this->current_cat ? $this->current_cat->term_id : $root_id);
|
||||
$list_args['child_of'] = $root_id;
|
||||
}
|
||||
|
||||
elseif ($show_children_only) {
|
||||
$list_args['child_of'] = 0;
|
||||
$list_args['depth'] = 1;
|
||||
$list_args['hierarchical'] = 1;
|
||||
}
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
|
||||
$menu_cat = new Elessi_Product_Cat_List_Walker();
|
||||
$menu_cat->set_icons($instance);
|
||||
$menu_cat->set_show_default($show_items);
|
||||
|
||||
$list_args['walker'] = $menu_cat;
|
||||
$list_args['title_li'] = '';
|
||||
$list_args['pad_counts'] = 1;
|
||||
$list_args['show_option_none'] = esc_html__('No product categories exist.', 'elessi-theme');
|
||||
$list_args['current_category'] = $this->current_cat ? $this->current_cat->term_id : '';
|
||||
$list_args['current_category_ancestors'] = $this->cat_ancestors;
|
||||
$list_args['max_depth'] = '';
|
||||
|
||||
if (!isset($nasa_opt['show_uncategorized']) || !$nasa_opt['show_uncategorized']) {
|
||||
$uncategorized = get_option('default_product_cat');
|
||||
|
||||
if ($uncategorized) {
|
||||
$list_args['exclude'] = $uncategorized;
|
||||
}
|
||||
}
|
||||
|
||||
$top3 = isset($nasa_opt['category_sidebar']) ? $nasa_opt['category_sidebar'] : 'top';
|
||||
$top3 = isset($_GET['sidebar']) ? $_GET['sidebar'] : $top3;
|
||||
|
||||
if ($top3 === 'top-3') {
|
||||
echo '<a data-show="1" class="nasa-tab-filter-topbar hidden-tag nasa-tab-push-cats" href="javascript:void(0);" data-text="' . esc_attr__('- Show less', 'elessi-theme') . '" rel="nofollow">' . esc_html__('+ Show more', 'elessi-theme') . '</a>';
|
||||
}
|
||||
|
||||
$accordion_class = $accordion ? ' nasa-accordion' : ' ns-ctree';
|
||||
|
||||
if ($get_sidebar == 'top') {
|
||||
$class_wrap_cat_top = 'nasa-widget-filter-cats-topbar';
|
||||
|
||||
if (isset($nasa_opt['top_bar_cat_pos']) && $nasa_opt['top_bar_cat_pos'] == 'top') {
|
||||
$accordion_class .= ' nasa-top-cat-filter';
|
||||
$class_wrap_cat_top .= ' nasa-top-cat-filter-wrap';
|
||||
}
|
||||
|
||||
echo '<div class="' . esc_attr($class_wrap_cat_top) . '">';
|
||||
}
|
||||
|
||||
echo '<ul class="nasa-product-categories-widget nasa-product-taxs-widget nasa-root-tax nasa-root-cat product-categories' . $accordion_class . '">';
|
||||
|
||||
wp_list_categories(apply_filters('woocommerce_product_categories_widget_args', $list_args));
|
||||
|
||||
if ($show_items && ($menu_cat->get_total_root() > $show_items)) {
|
||||
echo '<li class="nasa_show_manual"><a data-show="1" class="nasa-show" href="javascript:void(0);" data-text="' . esc_attr__('- Show less', 'elessi-theme') . '" rel="nofollow">' . esc_html__('+ Show more', 'elessi-theme') . '</a></li>';
|
||||
}
|
||||
|
||||
echo '<li class="nasa-current-note"></li>';
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
if ($get_sidebar == 'top') {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
$this->widget_end($args);
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists('WC_Product_Cat_List_Walker')) {
|
||||
require_once WC()->plugin_path() . '/includes/walkers/class-product-cat-list-walker.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Elessi_Product_Cat_List_Walker
|
||||
*
|
||||
* Extends from WC_Product_Cat_List_Walker
|
||||
*/
|
||||
class Elessi_Product_Cat_List_Walker extends WC_Product_Cat_List_Walker {
|
||||
|
||||
protected $_icons = array();
|
||||
protected $_k = 0;
|
||||
protected $_show_default = 0;
|
||||
protected $_max_depth = 0;
|
||||
|
||||
public function __construct($max_depth = 0) {
|
||||
$this->_max_depth = (int) $max_depth;
|
||||
}
|
||||
|
||||
public function set_icons($instance) {
|
||||
$this->_icons = $instance;
|
||||
}
|
||||
|
||||
public function set_show_default($show) {
|
||||
$this->_show_default = (int) $show;
|
||||
}
|
||||
|
||||
public function get_total_root() {
|
||||
return $this->_k;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::start_el()
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param int $depth Depth of category in reference to parents.
|
||||
* @param integer $current_object_id
|
||||
*/
|
||||
public function start_el(&$output, $cat, $depth = 0, $args = array(), $current_object_id = 0) {
|
||||
global $nasa_opt;
|
||||
|
||||
$output .= '<li class="nasa-tax-item cat-item cat-item-' . $cat->term_id . ' cat-item-' . $cat->slug;
|
||||
$nasa_active = $accordion = $icon = '';
|
||||
if ($depth == 0) {
|
||||
$output .= ' root-item';
|
||||
if ($this->_show_default && ($this->_k >= $this->_show_default)) {
|
||||
$output .= ' nasa-show-less';
|
||||
}
|
||||
$this->_k++;
|
||||
}
|
||||
if (isset($this->_icons['cat_' . $cat->slug]) && trim($this->_icons['cat_' . $cat->slug]) != '') {
|
||||
$icon = '<i class="nasa-icon ' . $this->_icons['cat_' . $cat->slug] . '"></i> ';
|
||||
}
|
||||
|
||||
if ($args['current_category'] == $cat->term_id) {
|
||||
$output .= ' current-cat current-tax-item active';
|
||||
$nasa_active = ' nasa-active';
|
||||
}
|
||||
|
||||
if ($args['has_children'] && $args['hierarchical'] && (!$this->_max_depth || (($depth + 1) < $this->_max_depth))) {
|
||||
$output .= ' cat-parent nasa-tax-parent li_accordion';
|
||||
$accordion = '<a href="javascript:void(0);" class="accordion" rel="nofollow"></a>';
|
||||
}
|
||||
|
||||
if ($args['current_category_ancestors'] && $args['current_category'] && in_array($cat->term_id, $args['current_category_ancestors'])) {
|
||||
$output .= ' nasa-current-tax-parent current-cat-parent active';
|
||||
}
|
||||
|
||||
$output .= '">' . $accordion;
|
||||
|
||||
$output .= '<a ' .
|
||||
'href="' . get_term_link($cat, $this->tree_type) . '" ' .
|
||||
'title="' . esc_attr($cat->name) . '" ' .
|
||||
'class="nasa-filter-item nasa-filter-by-tax nasa-filter-by-cat' . $nasa_active . '">' .
|
||||
$icon . $cat->name;
|
||||
|
||||
$output .= $args['show_count'] ? ' <span class="count">' . $cat->count . '</span>' : '';
|
||||
|
||||
$output .= '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_filter_alphabet_widget');
|
||||
|
||||
function elessi_product_filter_alphabet_widget() {
|
||||
register_widget('Elessi_WC_Widget_Alphabet_Filter');
|
||||
}
|
||||
|
||||
class Elessi_WC_Widget_Alphabet_Filter extends WC_Widget {
|
||||
|
||||
public static $_alphabet = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
public static $_request_name = 'first-letter';
|
||||
protected $_tax_query = array();
|
||||
protected $_meta_query = array();
|
||||
protected $_query = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_alphabet_filter nasa-any-filter nasa-widget-has-active';
|
||||
$this->widget_description = __('Display a list of alphabet to filter products.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_woocommerce_alphabet_filter';
|
||||
$this->widget_name = 'Nasa - Filter Product by Alphabet';
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __('Filter by Alphabet', 'elessi-theme'),
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
)
|
||||
);
|
||||
|
||||
add_filter('woocommerce_get_filtered_term_product_counts_query', array($this, 'filter_alphabet_product_query_count'));
|
||||
|
||||
add_filter('posts_where', array($this, 'fillter_by_first_character'), 10, 2);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom where SQL
|
||||
*
|
||||
* @global type $wpdb
|
||||
* @param type $where
|
||||
* @param type $query
|
||||
* @return type
|
||||
*/
|
||||
public function fillter_by_first_character($where, $query) {
|
||||
global $wpdb;
|
||||
|
||||
if (isset($_GET[self::$_request_name]) && !NASA_CORE_IN_ADMIN && $query->is_main_query()) {
|
||||
/**
|
||||
* Check is in archive product page
|
||||
*/
|
||||
$is_product_archive = is_shop() || is_product_taxonomy() ? true : false;
|
||||
|
||||
if (!$is_product_archive) {
|
||||
return $where;
|
||||
}
|
||||
|
||||
$search_terms = $_GET[self::$_request_name];
|
||||
|
||||
if (trim($search_terms) !== '') {
|
||||
$first_character = mb_substr($search_terms, 0, 1);
|
||||
$where .= $wpdb->prepare(' AND (' . $wpdb->posts . '.post_title LIKE %s)', $wpdb->esc_like($first_character) . '%');
|
||||
}
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count
|
||||
*
|
||||
* @param type $query
|
||||
* @return type
|
||||
*/
|
||||
public function filter_alphabet_product_query_count($query) {
|
||||
global $wpdb;
|
||||
|
||||
$search_terms = isset($_GET[self::$_request_name]) ? $_GET[self::$_request_name] : '';
|
||||
|
||||
if (!empty($search_terms)) {
|
||||
$first_character = mb_substr($search_terms, 0, 1);
|
||||
|
||||
$query['where'] .= $wpdb->prepare(' AND (' . $wpdb->posts . '.post_title LIKE %s)', $wpdb->esc_like($first_character) . '%');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_shop() && !is_product_taxonomy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
extract($args);
|
||||
|
||||
$link = elessi_get_origin_url();
|
||||
|
||||
if (!empty($_GET)) {
|
||||
foreach ($_GET as $key => $value) {
|
||||
if ($key != self::$_request_name) {
|
||||
$link = add_query_arg($key, esc_attr($value), $link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output = '<ul class="nasa-product-alphabet-widget small-block-grid-1 medium-block-grid-4 large-block-grid-6 nasa-after-clear">';
|
||||
|
||||
$filtered_alphabet = isset($_GET[self::$_request_name]) ? $_GET[self::$_request_name] : '';
|
||||
|
||||
/**
|
||||
* gen options HTML
|
||||
*/
|
||||
foreach (self::$_alphabet as $value) {
|
||||
$link_alphabet = $filtered_alphabet !== '' && $filtered_alphabet == $value ? $link : add_query_arg(self::$_request_name, $value, $link);
|
||||
$class = 'nasa-filter-alphabet';
|
||||
$class .= $filtered_alphabet == $value ? ' nasa-active' : '';
|
||||
|
||||
$output .= '<li><a class="' . esc_attr($class) . '" href="' . esc_url($link_alphabet) . '" title="' . esc_attr($value) . '" data-filter="first-letter">' . esc_html($value) . '</a></li>';
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
echo $output;
|
||||
$this->widget_end($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* Exit if accessed directly
|
||||
*/
|
||||
defined('ABSPATH') or die();
|
||||
|
||||
/**
|
||||
* Check WooCommerce Active
|
||||
*/
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_filter_multi_categories_widget');
|
||||
|
||||
function elessi_product_filter_multi_categories_widget() {
|
||||
register_widget('Elessi_WC_Widget_Multi_Categories_Filter');
|
||||
}
|
||||
|
||||
class Elessi_WC_Widget_Multi_Categories_Filter extends WC_Widget {
|
||||
|
||||
public static $_request_name = 'product_categories';
|
||||
|
||||
protected $_current_filters = array();
|
||||
|
||||
protected $_link = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_multi_categories_filter nasa-any-filter nasa-widget-has-active';
|
||||
$this->widget_description = __('Display a list of categories to filter products.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_woocommerce_multi_categories_filter';
|
||||
$this->widget_name = 'Nasa - Filter Product with Multi Categories';
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => 'Filter by Multi Categories',
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
'number' => array(
|
||||
'type' => 'text',
|
||||
'std' => 45,
|
||||
'label' => __('Number Categories', 'elessi-theme')
|
||||
),
|
||||
'list_cats' => array(
|
||||
'type' => 'text',
|
||||
'std' => '',
|
||||
'label' => __('Categories Included List (ID or Slug, separated by ",". Ex: 1, 2 or slug-1, slug-2)', 'elessi-theme')
|
||||
),
|
||||
);
|
||||
|
||||
if (!empty($_REQUEST[self::$_request_name])) {
|
||||
$this->_current_filters = is_array($_REQUEST[self::$_request_name]) ?
|
||||
$_REQUEST[self::$_request_name] : explode(',', wc_clean($_REQUEST[self::$_request_name]));
|
||||
|
||||
$this->_current_filters = array_map('sanitize_title', $this->_current_filters);
|
||||
}
|
||||
|
||||
add_action('woocommerce_product_query', array($this, 'filter_categories_product_query'));
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter by status product
|
||||
*
|
||||
* @param type $q
|
||||
*/
|
||||
public function filter_categories_product_query($q){
|
||||
if (empty($this->_current_filters)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$q_tax_query = $q->get('tax_query');
|
||||
$tax_query = !empty($q_tax_query) ? $q_tax_query : array();
|
||||
$tax_query[] = array(
|
||||
'taxonomy' => 'product_cat',
|
||||
'field' => 'slug',
|
||||
'terms' => $this->_current_filters,
|
||||
'operator' => 'IN'
|
||||
);
|
||||
|
||||
if (!empty($tax_query)) {
|
||||
$q->set('tax_query', $tax_query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build link cat
|
||||
*/
|
||||
protected function build_cat_link($cat) {
|
||||
$new_current = array();
|
||||
$class = 'nasa-filter-cat';
|
||||
|
||||
if (!in_array($cat->slug, $this->_current_filters)) {
|
||||
$new_current = $this->_current_filters;
|
||||
$new_current[] = $cat->slug;
|
||||
} else {
|
||||
$class .= ' nasa-active';
|
||||
foreach ($this->_current_filters as $value) {
|
||||
if ($value !== $cat->slug) {
|
||||
$new_current[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$link_cat = !empty($new_current) ? add_query_arg(self::$_request_name, implode(',', $new_current), $this->_link) : $this->_link;
|
||||
|
||||
$html = '<a title="' . esc_attr($cat->name) . '" class="' . $class . '" href="' . esc_url($link_cat) . '" data-filter="' . esc_attr($cat->slug) . '">' . esc_html($cat->name) . '</a>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_shop() && !is_product_taxonomy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number Cats show
|
||||
*/
|
||||
$number = isset($instance['number']) && (int) $instance['number'] ? (int) $instance['number'] : $this->settings['number']['std'];
|
||||
|
||||
/**
|
||||
* Slug Cats show
|
||||
*/
|
||||
$list_cats = isset($instance['list_cats']) && $instance['list_cats'] ? $instance['list_cats'] : $this->settings['list_cats']['std'];
|
||||
|
||||
if (trim($list_cats) !== '') {
|
||||
$product_categories = explode(',', trim($list_cats));
|
||||
|
||||
if ($product_categories) {
|
||||
foreach ($product_categories as $product_category) {
|
||||
$product_category = trim($product_category);
|
||||
if ($product_category != '') {
|
||||
/**
|
||||
* Query Cats
|
||||
*/
|
||||
$field = is_numeric($product_category) ? 'term_id' : 'slug';
|
||||
$term_include = get_term_by($field, $product_category, 'product_cat');
|
||||
|
||||
if ($term_include) {
|
||||
$cats[] = $term_include;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Query Cats
|
||||
*/
|
||||
$cats = get_terms(apply_filters('nasa_filter_cat_args', array(
|
||||
'number' => $number,
|
||||
'taxonomy' => 'product_cat',
|
||||
'orderby' => 'count',
|
||||
'order' => 'DESC'
|
||||
)));
|
||||
}
|
||||
|
||||
if (!$cats) {
|
||||
return;
|
||||
}
|
||||
|
||||
extract($args);
|
||||
|
||||
$this->_link = elessi_get_origin_url();
|
||||
|
||||
if (!empty($_GET)) {
|
||||
foreach ($_GET as $key => $value) {
|
||||
if ($key !== self::$_request_name) {
|
||||
$this->_link = add_query_arg($key, esc_attr($value), $this->_link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes()) {
|
||||
foreach ($_chosen_attributes as $attribute => $data) {
|
||||
$attr_name = 0 === strpos($attribute, 'pa_') ? substr($attribute, 3) : $attribute;
|
||||
$taxonomy_filter = 'filter_' . $attr_name;
|
||||
$this->_link = add_query_arg(esc_attr($taxonomy_filter), esc_attr(implode(',', $data['terms'])), $this->_link);
|
||||
|
||||
if ('or' == $data['query_type']) {
|
||||
$this->_link = add_query_arg(esc_attr(str_replace('pa_', 'query_type_', $attribute)), 'or', $this->_link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output = '<div class="nasa-filter-by-cats">';
|
||||
|
||||
foreach ($cats as $cat) {
|
||||
$output .= $this->build_cat_link($cat);
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
echo $output;
|
||||
$this->widget_end($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* Exit if accessed directly
|
||||
*/
|
||||
defined('ABSPATH') or die();
|
||||
|
||||
/**
|
||||
* Check WooCommerce Active
|
||||
*/
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_filter_tags_widget');
|
||||
|
||||
function elessi_product_filter_tags_widget() {
|
||||
register_widget('Elessi_WC_Widget_Tags_Filter');
|
||||
}
|
||||
|
||||
class Elessi_WC_Widget_Tags_Filter extends WC_Widget {
|
||||
|
||||
public static $_request_name = 'product-tags';
|
||||
|
||||
protected $_current_filters = array();
|
||||
|
||||
protected $_link = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_multi_tags_filter nasa-any-filter nasa-widget-has-active';
|
||||
$this->widget_description = __('Display a list of tags to filter products.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_woocommerce_multi_tags_filter';
|
||||
$this->widget_name = 'Nasa - Filter Product with Multi Tags';
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __('Filter by Tags', 'elessi-theme'),
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
'number' => array(
|
||||
'type' => 'text',
|
||||
'std' => 45,
|
||||
'label' => __('Number Tags', 'elessi-theme')
|
||||
),
|
||||
);
|
||||
|
||||
if (!empty($_REQUEST[self::$_request_name])) {
|
||||
$this->_current_filters = is_array($_REQUEST[self::$_request_name]) ?
|
||||
$_REQUEST[self::$_request_name] : explode(',', wc_clean($_REQUEST[self::$_request_name]));
|
||||
|
||||
$this->_current_filters = array_map('sanitize_title', $this->_current_filters);
|
||||
}
|
||||
|
||||
add_action('woocommerce_product_query', array($this, 'filter_tags_product_query'));
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter by status product
|
||||
*
|
||||
* @param type $q
|
||||
*/
|
||||
public function filter_tags_product_query($q){
|
||||
if (empty($this->_current_filters)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$q_tax_query = $q->get('tax_query');
|
||||
$tax_query = !empty($q_tax_query) ? $q_tax_query : array();
|
||||
$tax_query[] = array(
|
||||
'taxonomy' => 'product_tag',
|
||||
'field' => 'slug',
|
||||
'terms' => $this->_current_filters,
|
||||
'operator' => 'IN'
|
||||
);
|
||||
|
||||
if (!empty($tax_query)) {
|
||||
$q->set('tax_query', $tax_query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build link tag
|
||||
*/
|
||||
protected function build_tag_link($tag) {
|
||||
$new_current = array();
|
||||
$class = 'nasa-filter-tag';
|
||||
if (!in_array($tag->slug, $this->_current_filters)) {
|
||||
$new_current = $this->_current_filters;
|
||||
$new_current[] = $tag->slug;
|
||||
} else {
|
||||
$class .= ' nasa-active';
|
||||
foreach ($this->_current_filters as $value) {
|
||||
if ($value != $tag->slug) {
|
||||
$new_current[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$link_tag = !empty($new_current) ? add_query_arg(self::$_request_name, implode(',', $new_current), $this->_link) : $this->_link;
|
||||
|
||||
$html = '<a title="' . esc_attr($tag->name) . '" class="' . $class . '" href="' . esc_url($link_tag) . '" data-filter="' . esc_attr($tag->slug) . '">' . esc_html($tag->name) . '</a>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_shop() && !is_product_taxonomy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number Tags show
|
||||
*/
|
||||
$number = isset($instance['number']) && (int) $instance['number'] ? (int) $instance['number'] : $this->settings['number']['std'];
|
||||
|
||||
/**
|
||||
* Query Tags
|
||||
*/
|
||||
$tags = get_terms(apply_filters('nasa_filter_tags_args', array(
|
||||
'number' => $number,
|
||||
'taxonomy' => 'product_tag',
|
||||
'orderby' => 'count',
|
||||
'order' => 'DESC'
|
||||
)));
|
||||
|
||||
if (!$tags) {
|
||||
return;
|
||||
}
|
||||
|
||||
extract($args);
|
||||
|
||||
$this->_link = elessi_get_origin_url();
|
||||
|
||||
if (!empty($_GET)) {
|
||||
foreach ($_GET as $key => $value) {
|
||||
if ($key !== self::$_request_name) {
|
||||
$this->_link = add_query_arg($key, esc_attr($value), $this->_link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes()) {
|
||||
foreach ($_chosen_attributes as $attribute => $data) {
|
||||
$attr_name = 0 === strpos($attribute, 'pa_') ? substr($attribute, 3) : $attribute;
|
||||
$taxonomy_filter = 'filter_' . $attr_name;
|
||||
$this->_link = add_query_arg(esc_attr($taxonomy_filter), esc_attr(implode(',', $data['terms'])), $this->_link);
|
||||
|
||||
if ('or' == $data['query_type']) {
|
||||
$this->_link = add_query_arg(esc_attr(str_replace('pa_', 'query_type_', $attribute)), 'or', $this->_link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output = '<div class="nasa-filter-by-tags">';
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$output .= $this->build_tag_link($tag);
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
echo $output;
|
||||
$this->widget_end($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_filter_price_list_widget');
|
||||
|
||||
function elessi_product_filter_price_list_widget() {
|
||||
register_widget('Elessi_WC_Widget_Price_Filter_List');
|
||||
}
|
||||
|
||||
class Elessi_WC_Widget_Price_Filter_List extends WC_Widget {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_price_filter_list nasa-any-filter nasa-widget-has-active';
|
||||
$this->widget_description = __('Display a list of prices to filter products.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_woocommerce_price_filter_list';
|
||||
$this->widget_name = 'Nasa - Filter Product by Price (list)';
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __('Filter by price', 'elessi-theme'),
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
'price_range_size' => array(
|
||||
'type' => 'number',
|
||||
'step' => 1,
|
||||
'min' => 1,
|
||||
'max' => '',
|
||||
'std' => 50,
|
||||
'label' => __('Price range size', 'elessi-theme')
|
||||
),
|
||||
'max_price_ranges' => array(
|
||||
'type' => 'number',
|
||||
'step' => 1,
|
||||
'min' => 1,
|
||||
'max' => '',
|
||||
'std' => 10,
|
||||
'label' => __('Max price ranges', 'elessi-theme')
|
||||
),
|
||||
'hide_empty_ranges' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('Hide empty price ranges', 'elessi-theme')
|
||||
),
|
||||
'hide_decimal' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('Hide decimal price', 'elessi-theme')
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_shop() && !is_product_taxonomy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
extract($args);
|
||||
|
||||
$min_price = isset($_GET['min_price']) ? wc_clean(wp_unslash($_GET['min_price'])) : '';
|
||||
$max_price = isset($_GET['max_price']) ? wc_clean(wp_unslash($_GET['max_price'])) : '';
|
||||
$link = elessi_get_origin_url();
|
||||
|
||||
if (!empty($_GET)) {
|
||||
foreach ($_GET as $key => $value) {
|
||||
if (!in_array($key, array('min_price', 'max_price', 'paging-style'))) {
|
||||
$link = add_query_arg($key, esc_attr($value), $link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes()) {
|
||||
foreach ($_chosen_attributes as $attribute => $data) {
|
||||
$attr_name = 0 === strpos($attribute, 'pa_') ? substr($attribute, 3) : $attribute;
|
||||
$taxonomy_filter = 'filter_' . $attr_name;
|
||||
$link = add_query_arg(esc_attr($taxonomy_filter), esc_attr(implode(',', $data['terms'])), $link);
|
||||
|
||||
if ('or' == $data['query_type']) {
|
||||
$link = add_query_arg(esc_attr(str_replace('pa_', 'query_type_', $attribute)), 'or', $link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find min and max price in current result set
|
||||
$prices = elessi_get_filtered_price();
|
||||
$min = floor($prices->min_price);
|
||||
$max = ceil($prices->max_price);
|
||||
|
||||
if ($min == $max) {
|
||||
return;
|
||||
}
|
||||
|
||||
$price_range_size = isset($instance['price_range_size']) ? $instance['price_range_size'] : 50;
|
||||
$max_price_ranges = isset($instance['max_price_ranges']) ? $instance['max_price_ranges'] : 10;
|
||||
$hide_empty_ranges = isset($instance['hide_empty_ranges']) ? $instance['hide_empty_ranges'] : 0;
|
||||
$hide_decimal = isset($instance['hide_decimal']) ? $instance['hide_decimal'] : 0;
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
|
||||
// Apply WooCommerce filters on min and max prices (required for updating currency-switcher prices)
|
||||
$min = apply_filters('woocommerce_price_filter_widget_min_amount', $min);
|
||||
$max_unfiltered = $max;
|
||||
$max = apply_filters('woocommerce_price_filter_widget_max_amount', $max);
|
||||
|
||||
$count = 0;
|
||||
// If the filtered max-price (see above) is different from the original price (currency-switcher used) - apply "woocommerce_price_filter_widget_max_amount" filter to adapt price-range to the different prices
|
||||
if ($max_unfiltered != $max) {
|
||||
$range_size = round(apply_filters('woocommerce_price_filter_widget_max_amount', intval($price_range_size)), 0);
|
||||
} else {
|
||||
$range_size = intval($price_range_size);
|
||||
}
|
||||
|
||||
$max_ranges = (intval($max_price_ranges) - 1);
|
||||
|
||||
// Price descimals
|
||||
$wc_price_args = (!$hide_decimal) ? array() : array('decimals' => 0);
|
||||
|
||||
$output = '<ul class="nasa-price-filter-list">';
|
||||
|
||||
$output .= strlen($min_price) > 0 ?
|
||||
'<li class="nasa-all-price"><a class="nasa-filter-by-price-list" href="' . esc_url($link) . '"><span class="nasa-filter-price-text">' . esc_html__('All', 'elessi-theme') . '</span></a></li>' :
|
||||
'<li class="nasa-active nasa-all-price"><span class="nasa-filter-price-text">' . esc_html__('All', 'elessi-theme') . '</span></li>';
|
||||
|
||||
for ($range_min = 0; $range_min < ($max + $range_size); $range_min += $range_size) {
|
||||
$range_max = $range_min + $range_size;
|
||||
|
||||
// Hide empty price ranges?
|
||||
if (intval($hide_empty_ranges)) {
|
||||
// Are there products in this price range?
|
||||
if ($min > $range_max || ($max + $range_size) < $range_max || $range_min == $max) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$count++;
|
||||
|
||||
$min_price_output = wc_price($range_min, $wc_price_args);
|
||||
|
||||
if ($count == $max_ranges) {
|
||||
$price_output = '<span class="nasa-filter-price-text">' . $min_price_output . esc_html__('+', 'elessi-theme') . '</span>';
|
||||
|
||||
if ($range_min != $min_price) {
|
||||
$url = add_query_arg(array('min_price' => $range_min, 'max_price' => $max), $link);
|
||||
$output .= '<li><a class="nasa-filter-by-price-list" href="' . esc_url($url) . '" data-min="' . intval($range_min) . '" data-max="' . intval($range_max) . '">' . $price_output . '</a></li>';
|
||||
} else {
|
||||
$output .= '<li class="nasa-active">' . $price_output . '</li>';
|
||||
}
|
||||
|
||||
break; // Max price ranges limit reached, break loop
|
||||
} else {
|
||||
$price_output = '<span class="nasa-filter-price-text">' . $min_price_output . ' — ' . wc_price($range_min + $range_size, $wc_price_args) . '</span>';
|
||||
|
||||
if ($range_min != $min_price || $range_max != $max_price) {
|
||||
$url = add_query_arg(array('min_price' => $range_min, 'max_price' => $range_max), $link);
|
||||
$output .= '<li><a class="nasa-filter-by-price-list" href="' . esc_url($url) . '" data-min="' . intval($range_min) . '" data-max="' . intval($range_max) . '">' . $price_output . '</a></li>';
|
||||
} else {
|
||||
$output .= '<li class="nasa-active">' . $price_output . '</li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
|
||||
$output .= $min_price ? '<input type="hidden" name="min-price-list" value="' . $min_price . '" />' : '';
|
||||
$output .= $max_price ? '<input type="hidden" name="max-price-list" value="' . $max_price . '" />' : '';
|
||||
|
||||
echo $output;
|
||||
|
||||
$this->widget_end($args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* Price Filter Widget and related functions
|
||||
*
|
||||
* Generates a range slider to filter products by price.
|
||||
*
|
||||
* @author NasaThemes
|
||||
* @category Widgets
|
||||
* @version 1.0.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_filter_price_widget');
|
||||
function elessi_product_filter_price_widget() {
|
||||
register_widget('Elessi_WC_Widget_Price_Filter');
|
||||
}
|
||||
|
||||
class Elessi_WC_Widget_Price_Filter extends WC_Widget {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_price_filter nasa-price-filter-slide nasa-widget-has-active';
|
||||
$this->widget_description = __('Shows a price filter slider in a widget which lets you narrow down the list of shown products when viewing product categories.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_woocommerce_price_filter';
|
||||
$this->widget_name = __('Nasa - Filter Product by Price (slide)', 'elessi-theme');
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __('Filter by price', 'elessi-theme'),
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
'step' => array(
|
||||
'type' => 'number',
|
||||
'min' => '1',
|
||||
'std' => '10',
|
||||
'label' => __('Step Change', 'elessi-theme')
|
||||
),
|
||||
'btn_filter' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 0,
|
||||
'label' => __('Enable Button Filter', 'elessi-theme')
|
||||
),
|
||||
);
|
||||
|
||||
$plugin_url = WC()->plugin_url();
|
||||
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
|
||||
|
||||
wp_register_script('accounting', $plugin_url . '/assets/js/accounting/accounting' . $suffix . '.js', array('jquery'), '0.4.2', true);
|
||||
|
||||
wp_register_script('wc-jquery-ui-touchpunch', $plugin_url . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array('jquery-ui-slider'), WC_VERSION, true);
|
||||
|
||||
wp_register_script('wc-price-slider', $plugin_url . '/assets/js/frontend/price-slider' . $suffix . '.js', array('jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting'), WC_VERSION, true);
|
||||
|
||||
wp_localize_script('wc-price-slider', 'woocommerce_price_slider_params', array(
|
||||
// 'min_price' => isset($_GET['min_price']) ? esc_attr($_GET['min_price']) : '',
|
||||
// 'max_price' => isset($_GET['max_price']) ? esc_attr($_GET['max_price']) : '',
|
||||
'currency_format_num_decimals' => 0,
|
||||
'currency_format_symbol' => get_woocommerce_currency_symbol(),
|
||||
'currency_format_decimal_sep' => esc_attr(wc_get_price_decimal_separator()),
|
||||
'currency_format_thousand_sep' => esc_attr(wc_get_price_thousand_separator()),
|
||||
'currency_format' => esc_attr(str_replace(array('%1$s', '%2$s'), array('%s', '%v'), get_woocommerce_price_format())),
|
||||
));
|
||||
|
||||
if (is_customize_preview()) {
|
||||
wp_enqueue_script('wc-price-slider');
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the html at the start of a widget.
|
||||
*
|
||||
* @param array $args
|
||||
* @return string
|
||||
*/
|
||||
public function current_widget_start($args, $instance) {
|
||||
echo $args['before_widget'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the html at the end of a widget.
|
||||
*
|
||||
* @param array $args
|
||||
* @return string
|
||||
*/
|
||||
public function current_widget_end($args) {
|
||||
parent::widget_end($args);
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_shop() && !is_product_taxonomy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script('wc-price-slider');
|
||||
|
||||
$this->current_widget_start($args, $instance);
|
||||
|
||||
$_title = isset($instance['title']) ? $instance['title'] : esc_html__('Price', 'elessi-theme');
|
||||
$_step = isset($instance['step']) ? (int) $instance['step'] : 10;
|
||||
if ($_step <= 0) {
|
||||
$_step = 10;
|
||||
}
|
||||
$step = max(apply_filters('woocommerce_price_filter_widget_step', $_step), 1);
|
||||
|
||||
// $min_price = isset($_GET['min_price']) ? esc_attr($_GET['min_price']) : '';
|
||||
// $max_price = isset($_GET['max_price']) ? esc_attr($_GET['max_price']) : '';
|
||||
// $hasPrice = ($min_price !== '' && $max_price !== '' && ($min_price >= 0 || $max_price >= $min_price)) ?
|
||||
// true : false;
|
||||
// $class_reset = $hasPrice ? '' : ' hidden-tag';
|
||||
|
||||
// Find min and max price in current result set
|
||||
$prices = elessi_get_filtered_price();
|
||||
$min = $prices->min_price;
|
||||
$max = $prices->max_price;
|
||||
|
||||
$tax_display_mode = get_option('woocommerce_tax_display_shop');
|
||||
|
||||
if (wc_tax_enabled() && !wc_prices_include_tax() && 'incl' === $tax_display_mode) {
|
||||
// $tax_classes = array_merge(array(''), WC_Tax::get_tax_classes());
|
||||
$tax_class = apply_filters('woocommerce_price_filter_widget_tax_class', ''); // Uses standard tax class.
|
||||
$tax_rates = WC_Tax::get_rates($tax_class);
|
||||
|
||||
if ( $tax_rates ) {
|
||||
$min += WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax($min, $tax_rates));
|
||||
$max += WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax($max, $tax_rates) );
|
||||
}
|
||||
}
|
||||
|
||||
$min = apply_filters('woocommerce_price_filter_widget_min_amount', floor($min / $step) * $step);
|
||||
$max = apply_filters('woocommerce_price_filter_widget_max_amount', ceil($max / $step) * $step);
|
||||
|
||||
// WPCS: input var ok, CSRF ok.
|
||||
$min_price = isset($_GET['min_price']) ? floor(floatval(wp_unslash($_GET['min_price'])) / $step) * $step : $min;
|
||||
$max_price = isset($_GET['max_price']) ? ceil(floatval(wp_unslash($_GET['max_price'])) / $step) * $step : $max;
|
||||
|
||||
// $has_price = ($min_price !== '' && $max_price !== '' && ($min_price >= 0 || $max_price >= $min_price)) ? '1' : '0';
|
||||
// $class_reset = $has_price ? '' : ' hidden-tag';
|
||||
|
||||
if ($min_price < $min) {
|
||||
$min = $min_price;
|
||||
}
|
||||
|
||||
if ($max_price > $max) {
|
||||
$max = $max_price;
|
||||
}
|
||||
|
||||
if ($min == $max) {
|
||||
echo '<div id="' . $args['widget_id'] . '-ajax-wrap" class="nasa-hide-price nasa-filter-price-widget-wrap">' .
|
||||
$args['before_title'] . $_title . $args['after_title'] .
|
||||
'</div>';
|
||||
|
||||
$this->current_widget_end($args);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Round one more time
|
||||
*/
|
||||
$data_min = floor($min);
|
||||
$data_max = ceil($max);
|
||||
|
||||
$form_action = elessi_get_origin_url();
|
||||
$hide_btn = isset($instance['btn_filter']) && $instance['btn_filter'] ? false : true;
|
||||
|
||||
echo '<div id="' . $args['widget_id'] . '-ajax-wrap" class="nasa-filter-price-widget-wrap">';
|
||||
|
||||
if ($_title != '') {
|
||||
echo $args['before_title'] . $_title . $args['after_title'];
|
||||
}
|
||||
|
||||
wc_get_template(
|
||||
'content-widget-price-filter.php',
|
||||
array(
|
||||
'form_action' => $form_action,
|
||||
'step' => $step,
|
||||
'min_price' => $data_min,
|
||||
'max_price' => $data_max,
|
||||
'current_min_price' => $min_price,
|
||||
'current_max_price' => $max_price,
|
||||
'hide_btn' => $hide_btn,
|
||||
'nasa_widget' => true
|
||||
)
|
||||
);
|
||||
|
||||
echo '</div>';
|
||||
|
||||
$this->current_widget_end($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
add_action('widgets_init', 'elessi_product_filter_status_widget');
|
||||
|
||||
function elessi_product_filter_status_widget() {
|
||||
register_widget('Elessi_WC_Widget_Status_Filter');
|
||||
}
|
||||
|
||||
class Elessi_WC_Widget_Status_Filter extends WC_Widget {
|
||||
|
||||
public static $_status = array('on-sale', 'featured', 'in-stock', 'on-backorder');
|
||||
|
||||
protected $_tax_query = array();
|
||||
protected $_meta_query = array();
|
||||
protected $_query = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_status_filter nasa-any-filter nasa-widget-has-active';
|
||||
$this->widget_description = __('Display a list of status to filter products.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_woocommerce_status_filter';
|
||||
$this->widget_name = 'Nasa - Filter Product by Status';
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __('Filter by status', 'elessi-theme'),
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
|
||||
'filter_onsale' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('On Sale', 'elessi-theme')
|
||||
),
|
||||
|
||||
'filter_featured' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('Featured', 'elessi-theme')
|
||||
),
|
||||
|
||||
'filter_instock' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('In Stock', 'elessi-theme')
|
||||
),
|
||||
|
||||
'filter_onbackorder' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 1,
|
||||
'label' => __('On Backorders', 'elessi-theme')
|
||||
),
|
||||
);
|
||||
|
||||
add_action('woocommerce_product_query', array($this, 'filter_status_product_query'), 10, 1);
|
||||
|
||||
add_filter('woocommerce_get_filtered_term_product_counts_query', array($this, 'filter_status_product_query_count'));
|
||||
|
||||
if (isset($_GET['in-stock']) && $_GET['in-stock'] === '1' && 'yes' !== get_option('woocommerce_hide_out_of_stock_items')) {
|
||||
add_filter('option_woocommerce_hide_out_of_stock_items', function() {
|
||||
return 'yes';
|
||||
});
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ids On Sale
|
||||
*/
|
||||
protected function _ids_on_sale() {
|
||||
$ids_on_sale = wc_get_product_ids_on_sale();
|
||||
|
||||
return empty($ids_on_sale) ? array(0) : $ids_on_sale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter by status product
|
||||
*
|
||||
* @param type $q
|
||||
*/
|
||||
public function filter_status_product_query($q){
|
||||
/**
|
||||
* On sale
|
||||
*/
|
||||
if (isset($_GET['on-sale']) && $_GET['on-sale'] === '1') {
|
||||
$q->set('post__in', $this->_ids_on_sale());
|
||||
}
|
||||
|
||||
/**
|
||||
* Featured
|
||||
*/
|
||||
if (isset($_GET['featured']) && $_GET['featured'] === '1') {
|
||||
$this->build_tax_query($q);
|
||||
|
||||
$this->_tax_query[] = array(
|
||||
'taxonomy' => 'product_visibility',
|
||||
'field' => 'name',
|
||||
'terms' => 'featured'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* In stock
|
||||
*/
|
||||
if (isset($_GET['in-stock']) && $_GET['in-stock'] === '1' && 'yes' !== get_option('woocommerce_hide_out_of_stock_items')) {
|
||||
$visibility_terms = wc_get_product_visibility_term_ids();
|
||||
$terms_not_in = array($visibility_terms['exclude-from-catalog']);
|
||||
$terms_not_in[] = $visibility_terms['outofstock'];
|
||||
|
||||
if (!empty($terms_not_in)) {
|
||||
$this->build_tax_query($q);
|
||||
|
||||
$this->_tax_query[] = array(
|
||||
'taxonomy' => 'product_visibility',
|
||||
'field' => 'term_taxonomy_id',
|
||||
'terms' => $terms_not_in,
|
||||
'operator' => 'NOT IN',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On Backorder
|
||||
*/
|
||||
if (isset($_GET['on-backorder']) && $_GET['on-backorder'] === '1') {
|
||||
$this->build_meta_query($q);
|
||||
|
||||
$this->_meta_query[] = array(
|
||||
'key' => '_backorders',
|
||||
'value' => array('yes', 'notify'),
|
||||
'compare' => 'IN'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Tax Query
|
||||
*/
|
||||
if (!empty($this->_tax_query)) {
|
||||
$q->set('tax_query', $this->_tax_query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Meta Query
|
||||
*/
|
||||
if (!empty($this->_meta_query)) {
|
||||
$q->set('meta_query', $this->_meta_query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count
|
||||
*
|
||||
* @param type $query
|
||||
* @return type
|
||||
*/
|
||||
public function filter_status_product_query_count($query) {
|
||||
global $wpdb;
|
||||
|
||||
/* Count with Onsale */
|
||||
if (isset($_GET['on-sale']) && $_GET['on-sale'] === '1') {
|
||||
$id_onsale = $this->_ids_on_sale();
|
||||
|
||||
if (!empty($id_onsale)) {
|
||||
$query['where'] .= ' AND (' . $wpdb->posts . '.ID IN (' . implode(',', array_map('absint', $id_onsale)) . '))';
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $q
|
||||
* @param type $query
|
||||
*/
|
||||
protected function build_tax_query($q) {
|
||||
$this->_tax_query = empty($this->_tax_query) ? $q->get('tax_query') : $this->_tax_query;
|
||||
return empty($this->_tax_query) ? array() : $this->_tax_query;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $q
|
||||
* @param type $query
|
||||
*/
|
||||
protected function build_meta_query($q) {
|
||||
$this->_meta_query = empty($this->_meta_query) ? $q->get('meta_query') : $this->_meta_query;
|
||||
return empty($this->_meta_query) ? array() : $this->_meta_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_shop() && !is_product_taxonomy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$onsale = isset($instance['filter_onsale']) ? $instance['filter_onsale'] : $this->settings['filter_onsale']['std'];
|
||||
$featured = isset($instance['filter_featured']) ? $instance['filter_featured'] : $this->settings['filter_featured']['std'];
|
||||
$instock = isset($instance['filter_instock']) ? $instance['filter_instock'] : $this->settings['filter_instock']['std'];
|
||||
$onbackorder = isset($instance['filter_onbackorder']) ? $instance['filter_onbackorder'] : $this->settings['filter_onbackorder']['std'];
|
||||
|
||||
// $instock = 'yes' === get_option('woocommerce_hide_out_of_stock_items') ? false : $instock;
|
||||
|
||||
if (!$onsale && !$featured && !$instock && $onbackorder) {
|
||||
return;
|
||||
}
|
||||
|
||||
extract($args);
|
||||
|
||||
$link = elessi_get_origin_url();
|
||||
|
||||
if (!empty($_GET)) {
|
||||
foreach ($_GET as $key => $value) {
|
||||
if (!in_array($key, self::$_status)) {
|
||||
$link = add_query_arg($key, esc_attr($value), $link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes()) {
|
||||
foreach ($_chosen_attributes as $attribute => $data) {
|
||||
$attr_name = 0 === strpos($attribute, 'pa_') ? substr($attribute, 3) : $attribute;
|
||||
$taxonomy_filter = 'filter_' . $attr_name;
|
||||
$link = add_query_arg(esc_attr($taxonomy_filter), esc_attr(implode(',', $data['terms'])), $link);
|
||||
|
||||
if ('or' == $data['query_type']) {
|
||||
$link = add_query_arg(esc_attr(str_replace('pa_', 'query_type_', $attribute)), 'or', $link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output = '<ul class="nasa-product-status-widget small-block-grid-1 medium-block-grid-4 large-block-grid-4 nasa-after-clear">';
|
||||
|
||||
$onsale_filtered = isset($_GET['on-sale']) && $_GET['on-sale'] === '1' ? true : false;
|
||||
$featured_filtered = isset($_GET['featured']) && $_GET['featured'] === '1' ? true : false;
|
||||
$instock_filtered = isset($_GET['in-stock']) && $_GET['in-stock'] === '1' ? true : false;
|
||||
$onbackorder_filtered = isset($_GET['on-backorder']) && $_GET['on-backorder'] === '1' ? true : false;
|
||||
|
||||
/**
|
||||
* On sale
|
||||
*/
|
||||
if ($onsale) {
|
||||
$link_onsale = $onsale_filtered ? $link : add_query_arg('on-sale', '1', $link);
|
||||
$link_onsale = $featured_filtered ? add_query_arg('featured', '1', $link_onsale) : $link_onsale;
|
||||
$link_onsale = $instock_filtered ? add_query_arg('in-stock', '1', $link_onsale) : $link_onsale;
|
||||
$link_onsale = $onbackorder_filtered ? add_query_arg('on-backorder', '1', $link_onsale) : $link_onsale;
|
||||
$class = 'nasa-filter-status nasa-filter-onsale';
|
||||
$class .= $onsale_filtered ? ' nasa-active' : '';
|
||||
|
||||
$output .= '<li><a class="' . esc_attr($class) . '" href="' . esc_url($link_onsale) . '" title="' . esc_attr__('On Sale', 'elessi-theme') . '" data-filter="on-sale">' . esc_html__('On Sale', 'elessi-theme') . '</a></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Featured
|
||||
*/
|
||||
if ($featured) {
|
||||
$link_featured = $onsale_filtered ? add_query_arg('on-sale', '1', $link) : $link;
|
||||
$link_featured = $featured_filtered ? $link_featured : add_query_arg('featured', '1', $link_featured);
|
||||
$link_featured = $instock_filtered ? add_query_arg('in-stock', '1', $link_featured) : $link_featured;
|
||||
$link_featured = $onbackorder_filtered ? add_query_arg('on-backorder', '1', $link_featured) : $link_featured;
|
||||
$class = 'nasa-filter-status nasa-filter-feature';
|
||||
$class .= $featured_filtered ? ' nasa-active' : '';
|
||||
|
||||
$output .= '<li><a class="' . esc_attr($class) . '" href="' . esc_url($link_featured) . '" title="' . esc_attr__('Featured', 'elessi-theme') . '" data-filter="featured">' . esc_html__('Featured', 'elessi-theme') . '</a></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* In Stock
|
||||
*/
|
||||
if ($instock) {
|
||||
$link_instock = $onsale_filtered ? add_query_arg('on-sale', '1', $link) : $link;
|
||||
$link_instock = $featured_filtered ? add_query_arg('featured', '1', $link_instock) : $link_instock;
|
||||
$link_instock = $instock_filtered ? $link_instock : add_query_arg('in-stock', '1', $link_instock);
|
||||
$link_instock = $onbackorder_filtered ? add_query_arg('on-backorder', '1', $link_instock) : $link_instock;
|
||||
$class = 'nasa-filter-status nasa-filter-instock';
|
||||
$class .= $instock_filtered ? ' nasa-active' : '';
|
||||
|
||||
$output .= '<li><a class="' . esc_attr($class) . '" href="' . esc_url($link_instock) . '" title="' . esc_attr__('In Stock', 'elessi-theme') . '" data-filter="in-stock">' . esc_html__('In Stock', 'elessi-theme') . '</a></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* On Backorders
|
||||
*/
|
||||
if ($onbackorder) {
|
||||
$link_onbackorder = $onsale_filtered ? add_query_arg('on-sale', '1', $link) : $link;
|
||||
$link_onbackorder = $featured_filtered ? add_query_arg('featured', '1', $link_onbackorder) : $link_onbackorder;
|
||||
$link_onbackorder = $instock_filtered ? add_query_arg('in-stock', '1', $link_onbackorder) : $link_onbackorder;
|
||||
$link_onbackorder = $onbackorder_filtered ? $link_onbackorder : add_query_arg('on-backorder', '1', $link_onbackorder);
|
||||
$class = 'nasa-filter-status nasa-filter-onbackorder';
|
||||
$class .= $onbackorder_filtered ? ' nasa-active' : '';
|
||||
|
||||
$output .= '<li><a class="' . esc_attr($class) . '" href="' . esc_url($link_onbackorder) . '" title="' . esc_attr__('On Backorders', 'elessi-theme') . '" data-filter="on-backorder">' . esc_html__('On Backorders', 'elessi-theme') . '</a></li>';
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
echo $output;
|
||||
$this->widget_end($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
add_action('widgets_init', 'elessi_product_variations_widget');
|
||||
function elessi_product_variations_widget() {
|
||||
register_widget('Elessi_Product_Variations_Widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Layered Navigation Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
class Elessi_Product_Variations_Widget extends WC_Widget {
|
||||
|
||||
public static $nasa_widget_id = 'nasa_woocommerce_filter_variations';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_layered_nav nasa-widget-has-active';
|
||||
$this->widget_description = __('Shows a custom attribute in a widget which lets you narrow down the list of products when viewing product categories.', 'elessi-theme');
|
||||
$this->widget_id = self::$nasa_widget_id;
|
||||
$this->widget_name = 'Nasa - Filter Product by Attributes';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* update function.
|
||||
*
|
||||
* @see WP_Widget->update
|
||||
*
|
||||
* @param array $new_instance
|
||||
* @param array $old_instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function update($new_instance, $old_instance) {
|
||||
$this->init_settings($new_instance);
|
||||
|
||||
return parent::update($new_instance, $old_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* form function.
|
||||
*
|
||||
* @see WP_Widget->form
|
||||
*
|
||||
* @param array $instance
|
||||
*/
|
||||
public function form($instance) {
|
||||
$this->init_settings($instance);
|
||||
|
||||
if (empty($this->settings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo "<p class='nasa-widget-instance' data-instance='" . esc_attr(json_encode($instance)) . "'></p>";
|
||||
|
||||
foreach ($this->settings as $key => $setting) {
|
||||
$value = isset($instance[$key]) ? $instance[$key] : $setting['std'];
|
||||
$clss = isset($setting['class']) ? ' ' . $setting['class'] : '';
|
||||
|
||||
$_id = $this->get_field_id($key);
|
||||
$_name = $this->get_field_name($key);
|
||||
|
||||
switch ($setting['type']) {
|
||||
|
||||
case 'text' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<input class="widefat<?php echo esc_attr($clss); ?>" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="text" value="<?php echo esc_attr($value); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'number' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<input class="widefat<?php echo esc_attr($clss); ?>" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="number" step="<?php echo esc_attr($setting['step']); ?>" min="<?php echo esc_attr($setting['min']); ?>" max="<?php echo esc_attr($setting['max']); ?>" value="<?php echo esc_attr($value); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'select' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
<select class="widefat<?php echo esc_attr($clss); ?>" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" data-num="<?php echo esc_attr($this->number); ?>">
|
||||
<?php foreach ($setting['options'] as $option_key => $option_value) : ?>
|
||||
<option value="<?php echo esc_attr($option_key); ?>" <?php selected($option_key, $value); ?>><?php echo esc_html($option_value); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'checkbox' :
|
||||
?>
|
||||
<p>
|
||||
<input class="widefat<?php echo esc_attr($clss); ?>" id="<?php echo esc_attr($_id); ?>" name="<?php echo esc_attr($_name); ?>" type="checkbox" value="1" <?php checked($value, 1); ?> />
|
||||
<label for="<?php echo esc_attr($_id); ?>"><?php echo ($setting['label']); ?></label>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init settings after post types are registered
|
||||
*/
|
||||
public function init_settings($instance) {
|
||||
$attribute_array = array();
|
||||
$attribute_taxonomies = wc_get_attribute_taxonomies();
|
||||
|
||||
if ($attribute_taxonomies) {
|
||||
foreach ($attribute_taxonomies as $tax) {
|
||||
if (taxonomy_exists(wc_attribute_taxonomy_name($tax->attribute_name))) {
|
||||
$attribute_array[$tax->attribute_name] = $tax->attribute_label . ' ( ' . $tax->attribute_name . ' )';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __('Filter by', 'elessi-theme'),
|
||||
'label' => __('Title', 'elessi-theme')
|
||||
),
|
||||
'attribute' => array(
|
||||
'type' => 'select',
|
||||
'class' => 'nasa-select-attr',
|
||||
'std' => '',
|
||||
'label' => __('Attribute', 'elessi-theme'),
|
||||
'options' => $attribute_array
|
||||
),
|
||||
'query_type' => array(
|
||||
'type' => 'select',
|
||||
'std' => 'or',
|
||||
'label' => __('Query type', 'elessi-theme'),
|
||||
'options' => array(
|
||||
'or' => __('OR', 'elessi-theme'),
|
||||
'and' => __('AND', 'elessi-theme')
|
||||
)
|
||||
),
|
||||
'show_items' => array(
|
||||
'type' => 'text',
|
||||
'std' => 'All',
|
||||
'label' => __('Show default numbers items', 'elessi-theme')
|
||||
),
|
||||
'effect' => array(
|
||||
'type' => 'select',
|
||||
'std' => 'slide',
|
||||
'label' => __('Effect for show more and show less', 'elessi-theme'),
|
||||
'options' => array(
|
||||
'slide' => __('Slide Up-Down', 'elessi-theme'),
|
||||
'fade' => __('Fade In-Out', 'elessi-theme')
|
||||
)
|
||||
),
|
||||
'hide_empty' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 0,
|
||||
'label' => __('Hide empty', 'elessi-theme')
|
||||
),
|
||||
'count' => array(
|
||||
'type' => 'checkbox',
|
||||
'std' => 0,
|
||||
'label' => __('Show product counts', 'elessi-theme')
|
||||
),
|
||||
'cols' => array(
|
||||
'type' => 'select',
|
||||
'std' => '2',
|
||||
'label' => __('Columns - Classic Sidebar or Canvas Sidebar', 'elessi-theme'),
|
||||
'options' => array(
|
||||
'2' => __('2 Columns', 'elessi-theme'),
|
||||
'1' => __('1 Column', 'elessi-theme')
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get widget content
|
||||
$widget_data = elessi_get_content_widget_variation($args, $instance);
|
||||
|
||||
if (isset($widget_data['hide_widget']) && $widget_data['hide_widget']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
echo $widget_data['content'];
|
||||
$this->widget_end($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
if (class_exists('WP_Widget')) {
|
||||
|
||||
add_action('widgets_init', 'elessi_posts_widget');
|
||||
function elessi_posts_widget() {
|
||||
register_widget('Elessi_Post_Widget');
|
||||
}
|
||||
|
||||
class Elessi_Post_Widget extends WP_Widget {
|
||||
|
||||
/**
|
||||
*
|
||||
* Contructor
|
||||
*/
|
||||
function __construct() {
|
||||
$widget_ops = array(
|
||||
'classname' => 'widget_nasa_posts',
|
||||
'description' => __('Nasa widget displays recent posts', 'elessi-theme')
|
||||
);
|
||||
|
||||
parent::__construct('nasa_posts', 'Nasa - Posts', $widget_ops);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Render widget content
|
||||
*/
|
||||
function widget($args, $instance) {
|
||||
if (!isset($args['widget_id'])) {
|
||||
$args['widget_id'] = $this->id;
|
||||
}
|
||||
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? esc_html__('Recent Posts', 'elessi-theme') : $instance['title'], $instance, $this->id_base);
|
||||
$number = !empty($instance['number']) && (int) $instance['number'] ? (int) $instance['number'] : 5;
|
||||
|
||||
$r = new WP_Query(apply_filters('widget_posts_args', array(
|
||||
'posts_per_page' => $number,
|
||||
'no_found_rows' => true,
|
||||
'post_status' => 'publish',
|
||||
'ignore_sticky_posts' => true,
|
||||
), $instance));
|
||||
|
||||
if ($r->have_posts()) :
|
||||
echo ($args['before_widget']);
|
||||
echo ($title) ? $args['before_title'] . $title . $args['after_title'] : ''; ?>
|
||||
<ul>
|
||||
<?php
|
||||
while ($r->have_posts()) :
|
||||
$r->the_post();
|
||||
$title_post = get_the_title();
|
||||
$link_post = get_the_permalink();
|
||||
$categories = get_the_category_list(', ');
|
||||
$class_col = 'large-12 columns';
|
||||
?>
|
||||
<li class="nasa-recent-posts-li">
|
||||
<div class="row">
|
||||
<?php if (has_post_thumbnail()) : ?>
|
||||
<div class="large-4 medium-4 small-4 columns nasa-thumbnail-post rtl-right">
|
||||
<a href="<?php echo esc_url($link_post); ?>" title="<?php echo esc_attr($title_post); ?>">
|
||||
<?php the_post_thumbnail('thumbnail'); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
$class_col = 'large-8 medium-8 small-8 columns rtl-right';
|
||||
endif; ?>
|
||||
<div class="<?php echo esc_attr($class_col); ?> nasa-info-post">
|
||||
<div class="nasa-post-cats-wrap"><?php echo $categories; ?></div>
|
||||
<a class="nasa-wg-recent-post-title" href="<?php echo esc_url($link_post); ?>" title="<?php echo esc_attr($title_post); ?>">
|
||||
<?php echo $title_post; ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endwhile; ?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
echo ($args['after_widget']);
|
||||
|
||||
wp_reset_postdata();
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Update instance
|
||||
*/
|
||||
function update($new_instance, $old_instance) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['number'] = (int) $new_instance['number'];
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Render widget form dashboard
|
||||
*/
|
||||
function form($instance) {
|
||||
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
|
||||
$number = isset($instance['number']) ? absint($instance['number']) : 5;
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:', 'elessi-theme'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('number')); ?>"><?php esc_html_e('Number of posts to show:', 'elessi-theme'); ?></label>
|
||||
<input id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3" />
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* Widget Nasa Reset Filter
|
||||
*/
|
||||
if (NASA_WOO_ACTIVED) {
|
||||
|
||||
/**
|
||||
* Register Widget
|
||||
*/
|
||||
add_action('widgets_init', 'elessi_reset_filter_widget');
|
||||
function elessi_reset_filter_widget() {
|
||||
register_widget('Elessi_WC_Widget_Reset_Filters');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset Filter Widget and related functions
|
||||
*
|
||||
* @author NasaThemes
|
||||
* @category Widgets
|
||||
* @version 1.0.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
class Elessi_WC_Widget_Reset_Filters extends WC_Widget {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->widget_cssclass = 'woocommerce widget_reset_filters nasa-slick-remove nasa-no-toggle nasa-widget-has-active nasa-widget-hidden';
|
||||
$this->widget_description = __('Display button reset filter.', 'elessi-theme');
|
||||
$this->widget_id = 'nasa_woocommerce_reset_filter';
|
||||
$this->widget_name = 'Nasa - Reset Filters';
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => '',
|
||||
'label' => __('Title', 'elessi-theme'),
|
||||
),
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output widget.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @param array $args Arguments.
|
||||
* @param array $instance Widget instance.
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
if (!is_shop() && !is_product_taxonomy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
|
||||
$min_price = isset($_GET['min_price']) ? wc_clean(wp_unslash($_GET['min_price'])) : 0;
|
||||
$max_price = isset($_GET['max_price']) ? wc_clean(wp_unslash($_GET['max_price'])) : 0;
|
||||
$rating_filter = isset($_GET['rating_filter']) ? array_filter(array_map('absint', explode(',', wp_unslash($_GET['rating_filter'])))) : array();
|
||||
$status_filter = false;
|
||||
if (class_exists('Elessi_WC_Widget_Status_Filter')) {
|
||||
foreach (Elessi_WC_Widget_Status_Filter::$_status as $status) {
|
||||
if (isset($_REQUEST[$status]) && $_REQUEST[$status] === '1') {
|
||||
$status_filter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$alphabet_filter = false;
|
||||
if (class_exists('Elessi_WC_Widget_Alphabet_Filter')) {
|
||||
if (isset($_REQUEST[Elessi_WC_Widget_Alphabet_Filter::$_request_name]) && trim($_REQUEST[Elessi_WC_Widget_Alphabet_Filter::$_request_name]) !== '') {
|
||||
$alphabet_filter = true;
|
||||
}
|
||||
}
|
||||
|
||||
$tags_filter = false;
|
||||
if (class_exists('Elessi_WC_Widget_Tags_Filter')) {
|
||||
if (isset($_REQUEST[Elessi_WC_Widget_Tags_Filter::$_request_name]) && !empty($_REQUEST[Elessi_WC_Widget_Tags_Filter::$_request_name])) {
|
||||
$tags_filter = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$cat_filter = false;
|
||||
if (class_exists('Elessi_WC_Widget_Multi_Categories_Filter')) {
|
||||
if (isset($_REQUEST[Elessi_WC_Widget_Multi_Categories_Filter::$_request_name]) && !empty($_REQUEST[Elessi_WC_Widget_Multi_Categories_Filter::$_request_name])) {
|
||||
$cat_filter = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < count($_chosen_attributes) || 0 < $min_price || 0 < $max_price || !empty($rating_filter) || $status_filter || $alphabet_filter || $tags_filter || $cat_filter) {
|
||||
global $wp_query;
|
||||
|
||||
$title = isset($instance['title']) && $instance['title'] ? $instance['title'] : esc_html__('Reset', 'elessi-theme');
|
||||
|
||||
$nasa_href_page = elessi_get_origin_url_paging(array('s', 'post_type'));
|
||||
|
||||
// Reset Price, Rating Filter
|
||||
$reset_arrays = array('min_price', 'max_price', 'rating_filter');
|
||||
|
||||
// Reset Status Filter
|
||||
if ($status_filter) {
|
||||
$reset_arrays = array_merge($reset_arrays, Elessi_WC_Widget_Status_Filter::$_status);
|
||||
}
|
||||
|
||||
// Reset Alphabet Filter
|
||||
if ($alphabet_filter) {
|
||||
$reset_arrays[] = Elessi_WC_Widget_Alphabet_Filter::$_request_name;
|
||||
}
|
||||
|
||||
// Reset Multi Tags Filter
|
||||
if ($tags_filter) {
|
||||
$reset_arrays[] = Elessi_WC_Widget_Tags_Filter::$_request_name;
|
||||
}
|
||||
|
||||
// Reset Multi Categories Filter
|
||||
if ($cat_filter) {
|
||||
$reset_arrays[] = Elessi_WC_Widget_Multi_Categories_Filter::$_request_name;
|
||||
}
|
||||
|
||||
// Reset Attributes Filter
|
||||
$array_add = array();
|
||||
if (!empty($_GET) && count($_chosen_attributes)) {
|
||||
foreach ($_GET as $key => $value) {
|
||||
if (0 === strpos($key, 'filter_')) {
|
||||
$attribute = wc_sanitize_taxonomy_name(str_replace('filter_', '', $key));
|
||||
$reset_arrays[] = $key;
|
||||
$reset_arrays[] = 'query_type_' . $attribute;
|
||||
} else {
|
||||
if (!in_array($key, $reset_arrays)) {
|
||||
$array_add[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nasa_href_page = remove_query_arg($reset_arrays, add_query_arg($array_add, $nasa_href_page));
|
||||
$_close_svg = '<svg class="nasa-close-fillter" width="20px" height="12px" viewBox="0 0 24 24" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M19.207 6.207a1 1 0 0 0-1.414-1.414L12 10.586 6.207 4.793a1 1 0 0 0-1.414 1.414L10.586 12l-5.793 5.793a1 1 0 1 0 1.414 1.414L12 13.414l5.793 5.793a1 1 0 0 0 1.414-1.414L13.414 12l5.793-5.793z" fill="Curentcolor" /></svg>';
|
||||
|
||||
$this->widget_start($args, $instance);
|
||||
|
||||
echo '<a class="nasa-reset-filters-btn" href="' . esc_url($nasa_href_page) . '" title="' . $title . '">' . $_close_svg . $title . '</a>';
|
||||
|
||||
$this->widget_end($args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die(); // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* Register Widget
|
||||
*/
|
||||
add_action('widgets_init', 'elessi_tag_cloud_widget');
|
||||
function elessi_tag_cloud_widget() {
|
||||
register_widget('Elessi_Widget_Tag_Cloud');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags Cloud Widget
|
||||
*/
|
||||
class Elessi_Widget_Tag_Cloud extends WP_Widget {
|
||||
|
||||
/**
|
||||
* Sets up a new Ace Tag Cloud widget instance.
|
||||
*/
|
||||
public function __construct() {
|
||||
$widget_ops = array(
|
||||
'description' => __('A cloud of your most used tags.', 'elessi-theme'),
|
||||
'customize_selective_refresh' => true,
|
||||
'title' => __('Tags', 'elessi-theme'),
|
||||
'show_items' => 'All'
|
||||
);
|
||||
|
||||
parent::__construct('nasa_tag_cloud', 'Nasa - Tag Cloud', $widget_ops);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
$class = 'tagcloud';
|
||||
|
||||
if (isset($instance['taxonomy']) && in_array($instance['taxonomy'], array('product_cat', 'product_tag'))) {
|
||||
$class .= ' nasa-tag-cloud';
|
||||
$class .= $instance['taxonomy'] == 'product_tag' ? ' nasa-tag-products-cloud' : '';
|
||||
}
|
||||
|
||||
$current_taxonomy = $this->_get_current_taxonomy($instance);
|
||||
$title_widget = !empty($instance['title']) ? $instance['title'] : ('post_tag' == $current_taxonomy ? esc_html__('Tags', 'elessi-theme') : get_taxonomy($current_taxonomy)->labels->name);
|
||||
|
||||
/** This filter is documented in wp-includes/default-widgets.php */
|
||||
$title = apply_filters('widget_title', $title_widget, $instance, $this->id_base);
|
||||
|
||||
echo $args['before_widget'];
|
||||
|
||||
echo $title ? $args['before_title'] . $title . $args['after_title'] : '';
|
||||
|
||||
echo '<div class="' . $class . '">';
|
||||
|
||||
$show_items = isset($instance['show_items']) ? (int) $instance['show_items'] : 0;
|
||||
|
||||
$tags = wp_tag_cloud(apply_filters('widget_tag_cloud_args', array(
|
||||
'taxonomy' => $current_taxonomy,
|
||||
'format' => 'array'
|
||||
)));
|
||||
|
||||
if ($tags) {
|
||||
echo '<ul class="nasa-tag-cloud-ul">';
|
||||
|
||||
foreach ($tags as $k => $tag) {
|
||||
$class_li = ($show_items && $k+1 > $show_items) ? ' class="nasa-show-less"' : '';
|
||||
echo '<li' . $class_li . '>' . $tag . '</li>';
|
||||
}
|
||||
|
||||
if ($show_items) {
|
||||
echo
|
||||
'<li class="nasa_show_manual" data-delay="500" data-fadein="1">' .
|
||||
'<a data-show="1" class="nasa-show" href="javascript:void(0);" data-text="' . esc_attr__('- Show less', 'elessi-theme') . '" rel="nofollow">' .
|
||||
esc_html__('+ Show more', 'elessi-theme') .
|
||||
'</a>' .
|
||||
'</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
echo "</div>\n";
|
||||
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles updating settings for the current Tag Cloud widget instance.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $new_instance New settings for this instance as input by the user via
|
||||
* WP_Widget::form().
|
||||
* @param array $old_instance Old settings for this instance.
|
||||
* @return array Settings to save or bool false to cancel saving.
|
||||
*/
|
||||
public function update($new_instance, $old_instance) {
|
||||
$instance = array();
|
||||
$instance['title'] = sanitize_text_field($new_instance['title']);
|
||||
$instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
|
||||
$instance['show_items'] = sanitize_text_field($new_instance['show_items']);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the Tag Cloud widget settings form.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $instance Current settings.
|
||||
*/
|
||||
public function form($instance) {
|
||||
$current_taxonomy = $this->_get_current_taxonomy($instance);
|
||||
$title_id = esc_attr($this->get_field_id('title'));
|
||||
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
|
||||
|
||||
echo
|
||||
'<p>' .
|
||||
'<label for="' . $title_id . '">' . esc_html__('Title:', 'elessi-theme') . '</label>' .
|
||||
'<input type="text" class="widefat" id="' . $title_id . '" name="' . esc_attr($this->get_field_name('title')) . '" value="' . $title . '" />' .
|
||||
'</p>';
|
||||
|
||||
$taxonomies = get_taxonomies(array('show_tagcloud' => true), 'object');
|
||||
$id = esc_attr($this->get_field_id('taxonomy'));
|
||||
$name = esc_attr($this->get_field_name('taxonomy'));
|
||||
$input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
|
||||
|
||||
switch (count($taxonomies)) {
|
||||
// No tag cloud supporting taxonomies found, display error message
|
||||
case 0:
|
||||
echo '<p>' . esc_html__('The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.', 'elessi-theme') . '</p>';
|
||||
printf($input, '');
|
||||
break;
|
||||
|
||||
// Just a single tag cloud supporting taxonomy found, no need to display options
|
||||
case 1:
|
||||
$keys = array_keys($taxonomies);
|
||||
$taxonomy = reset($keys);
|
||||
printf($input, esc_attr($taxonomy));
|
||||
break;
|
||||
|
||||
// More than one tag cloud supporting taxonomy found, display options
|
||||
default:
|
||||
printf(
|
||||
'<p><label for="%1$s">%2$s</label><select class="widefat" id="%1$s" name="%3$s">',
|
||||
$id,
|
||||
esc_html__('Taxonomy:', 'elessi-theme'),
|
||||
$name
|
||||
);
|
||||
|
||||
foreach ($taxonomies as $taxonomy => $tax) {
|
||||
printf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
esc_attr($taxonomy),
|
||||
selected($taxonomy, $current_taxonomy, false),
|
||||
$tax->labels->name
|
||||
);
|
||||
}
|
||||
|
||||
echo '</select></p>';
|
||||
}
|
||||
|
||||
$show_items = $this->get_field_id('show_items');
|
||||
$val_show = (isset($instance['show_items']) && is_numeric($instance['show_items']) ? $instance['show_items'] : esc_attr__('All', 'elessi-theme'));
|
||||
|
||||
echo
|
||||
'<p>' .
|
||||
'<label for="' . esc_attr($show_items) . '">' . esc_html__('Show items (0 ~ All)', 'elessi-theme') . '</label>' .
|
||||
'<input type="text" class="widefat" id="' . esc_attr($show_items) . '" name="' . esc_attr($this->get_field_name('show_items')) . '" value="' . $val_show . '" />' .
|
||||
'</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the taxonomy for the current Tag cloud widget instance.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $instance Current settings.
|
||||
* @return string Name of the current taxonomy if set, otherwise 'post_tag'.
|
||||
*/
|
||||
public function _get_current_taxonomy($instance) {
|
||||
if (!empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy'])) {
|
||||
return $instance['taxonomy'];
|
||||
}
|
||||
|
||||
return 'post_tag';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user