widget_cssclass = 'ccas_ajax_layered_nav_widget_id'; $this->widget_description = __( 'Shows a custom attribute in a widget which lets you search products based on attributes.', 'ajaxify-filters' ); $this->widget_id = 'ccas_ajax_layered_nav'; $this->widget_name = __( 'AJAX Product Attributes', 'ajaxify-filters' ); parent::__construct(); } /** * Updates a particular instance of a widget. */ public function update( $new_instance, $old_instance ) { return $new_instance; } /** * Outputs the settings update form. */ public function form( $instance ) { $this->init_settings(); parent::form( $instance ); if(isset($instance["display_type"])) { $thisRef = $this->get_field_name(""); $thisRef = explode("]",$thisRef )[0]; $thisRef = $thisRef.']'; $instanceRef = $instance; $selectedOpt = $instance["display_type"]; $selectedAttribute = $instance['attribute']; $terms = get_terms ( 'pa_' . $selectedAttribute ); echo '
'; if ($selectedOpt == "label") { require_once CED_CAF_PLUGIN_DIR_PATH.'/core/labelLook.php'; } else if ($selectedOpt == "picker") { require_once CED_CAF_PLUGIN_DIR_PATH.'/core/pickerLook.php'; } echo '
'; } else { //an empty div to to filled by ajax-data-fetch request (dynamically) echo ''; } echo ''; } /** * Init settings after post types are registered. */ public function init_settings() { $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_name; } } } $this->settings = array( 'title' => array( 'type' => 'text', 'std' => __( 'Filter By', 'ajaxify-filters' ), 'label' => __( 'Title', 'ajaxify-filters' ) ), 'multiple_filter' => array( //updated 'type' => 'checkbox', 'std' => 0, 'class' => 'ccas_multiple_filter', 'label' => __( 'Enable Multiple Filter', 'ajaxify-filters' ) ), 'query_type' => array( 'type' => 'select', 'std' => 'and', 'class' => 'ccas_query_type', 'label' => __( 'Query type', 'ajaxify-filters' ), 'options' => array( 'and' => __( 'AND', 'ajaxify-filters' ), 'or' => __( 'OR', 'ajaxify-filters' ) ) ), 'count' => array( //updated 'type' => 'checkbox', 'std' => 0, 'label' => __( 'Show product counts', 'ajaxify-filters' ) ), 'attribute' => array( 'type' => 'select_attribute', 'std' => '', 'label' => __( 'Attribute', 'ajaxify-filters' ), 'options' => $attribute_array ), 'display_type' => array( 'type' => 'select_display_type', 'std' => 'list', 'class' => 'ccas_attribute_urgent', 'label' => __( 'Display type', 'ajaxify-filters' ), 'options' => array( 'list' => __( 'List', 'ajaxify-filters' ), 'checkbox' => __( 'Checkbox', 'ajaxify-filters' ), 'label' => __( 'Size/Amount Selector', 'ajaxify-filters' ), 'picker' => __( 'Color Selector', 'ajaxify-filters' ), ) ), ); } /** * Output widget. */ public function widget( $args, $instance ) { global $_chosen_attributes; global $ccas_filtered_pro_ids; if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) { return; } $current_term = is_tax() ? get_queried_object()->term_id : ''; $current_tax = is_tax() ? get_queried_object()->taxonomy : ''; $taxonomy = isset( $instance['attribute'] ) ? wc_attribute_taxonomy_name( $instance['attribute'] ) : $this->settings['attribute']['std']; $query_type = isset( $instance['query_type'] ) ? $instance['query_type'] : $this->settings['query_type']['std']; $display_type = isset( $instance['display_type'] ) ? $instance['display_type'] : $this->settings['display_type']['std']; $isShowCount = isset( $instance['count'] ) ? $instance['count'] : $this->settings['count']['std'];//updated $is_multiple_filter = isset( $instance['multiple_filter'] ) ? $instance['multiple_filter'] : $this->settings['multiple_filter']['std'];//updated if ( ! taxonomy_exists( $taxonomy ) ) { return; } $get_terms_args = array( 'hide_empty' => '1' ); $orderby = wc_attribute_orderby( $taxonomy ); switch ( $orderby ) { case 'name' : $get_terms_args['orderby'] = 'name'; $get_terms_args['menu_order'] = false; break; case 'id' : $get_terms_args['orderby'] = 'id'; $get_terms_args['order'] = 'ASC'; $get_terms_args['menu_order'] = false; break; case 'menu_order' : $get_terms_args['menu_order'] = 'ASC'; break; } $terms = get_terms( $taxonomy, $get_terms_args ); if ( 0 < count( $terms ) ) { //ob_start(); $found = false; $this->widget_start( $args, $instance ); // Force found when option is selected - do not force found on taxonomy attributes if ( ! is_tax() && is_array( $_chosen_attributes ) && array_key_exists( $taxonomy, $_chosen_attributes ) ) { $found = true; } if($display_type == "picker") { echo '