Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
home
/
getwphos
/
www
/
techniquetechs
/
wp-content
/
themes
/
plexify
/
inc
/
widgets
/
File Content:
product-layered-nav.php
<?php if (!class_exists('Woocommerce')) return; use Automattic\WooCommerce\Internal\ProductAttributesLookup\Filterer; defined( 'ABSPATH' ) || exit; if(!function_exists('pxl_register_wp_widget')) return; add_action( 'widgets_init', function(){ pxl_register_wp_widget( 'Plexify_Product_Layered_Nav_Widget' ); }); class Plexify_Product_Layered_Nav_Widget extends WC_Widget { public function __construct() { $this->widget_cssclass = 'pxl-widget widget_layered_nav woocommerce-widget-layered-nav pxl-widget-layered-nav'; $this->widget_description = esc_html__( 'Display a list of attributes to filter products in your store.', 'plexify' ); $this->widget_id = 'pxl_wc_layered_nav'; $this->widget_name = esc_html__( '* PXL Filter Products by Attribute', 'plexify' ); parent::__construct(); } public function update( $new_instance, $old_instance ) { $this->init_settings(); return parent::update( $new_instance, $old_instance ); } public function form( $instance ) { $this->init_settings(); parent::form( $instance ); } public function init_settings() { $attribute_array = array(); $std_attribute = ''; $attribute_taxonomies = wc_get_attribute_taxonomies(); if ( ! empty( $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; } } $std_attribute = current( $attribute_array ); } $this->settings = array( 'title' => array( 'type' => 'text', 'std' => esc_html__( 'Filter by', 'plexify' ), 'label' => esc_html__( 'Title', 'plexify' ), ), 'attribute' => array( 'type' => 'select', 'std' => $std_attribute, 'label' => esc_html__( 'Attribute', 'plexify' ), 'options' => $attribute_array, ), 'display_type' => array( 'type' => 'select', 'std' => 'list', 'label' => esc_html__( 'Display type', 'plexify' ), 'options' => array( 'list' => esc_html__( 'List', 'plexify' ), 'inline' => esc_html__( 'Inline', 'plexify' ), 'dropdown' => esc_html__( 'Dropdown', 'plexify' ), ), ), 'list_style' => array( 'type' => 'select', 'std' => 'df', 'label' => esc_html__( 'List Style (For Display type in list, inline)', 'plexify' ), 'options' => array( 'df' => esc_html__( 'Default List', 'plexify' ), 'checkbox' => esc_html__( 'Check List', 'plexify' ), 'swatches' => esc_html__( 'Swatches List', 'plexify' ), ), ), 'show_labels' => array( 'type' => 'select', 'std' => 'on', 'label' => esc_html__( 'Show label (For Swatches list style)', 'plexify' ), 'options' => array( 'on' => esc_html__( 'On', 'plexify' ), 'off' => esc_html__( 'Off', 'plexify' ), ), ), 'query_type' => array( 'type' => 'select', 'std' => 'and', 'label' => esc_html__( 'Query type', 'plexify' ), 'options' => array( 'and' => esc_html__( 'AND', 'plexify' ), 'or' => esc_html__( 'OR', 'plexify' ), ), ), 'items_count' => array( 'type' => 'select', 'std' => 'on', 'label' => esc_html__( 'Show items count', 'plexify' ), 'options' => array( 'on' => esc_html__( 'On', 'plexify' ), 'off' => esc_html__( 'Off', 'plexify' ), ), ), 'enable_scrollable' => array( 'type' => 'checkbox', 'std' => 0, 'label' => esc_html__( 'Enable scrollable (For List style)', 'plexify' ), ), 'scrollable_height' => array( 'type' => 'text', 'std' => '120px', 'label' => esc_html__( 'Scrollable height (For Scrollable Enable)', 'plexify' ), ), 'enable_collapse' => array( 'type' => 'checkbox', 'std' => 0, 'label' => esc_html__( 'Enable Collapse (For List style)', 'plexify' ), ), 'enable_load_more' => array( 'type' => 'checkbox', 'std' => 0, 'label' => esc_html__( 'Enable Load More (For List style)', 'plexify' ), ), 'items_loadmore_display' => array( 'type' => 'text', 'std' => '4', 'label' => esc_html__( 'Items Display (For Load More Enable)', 'plexify' ), ), ); } protected function get_instance_taxonomy( $instance ) { if ( isset( $instance['attribute'] ) ) { return wc_attribute_taxonomy_name( $instance['attribute'] ); } $attribute_taxonomies = wc_get_attribute_taxonomies(); if ( ! empty( $attribute_taxonomies ) ) { foreach ( $attribute_taxonomies as $tax ) { if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) ) { return wc_attribute_taxonomy_name( $tax->attribute_name ); } } } return ''; } protected function get_instance_query_type( $instance ) { return isset( $instance['query_type'] ) ? $instance['query_type'] : 'and'; } protected function get_instance_display_type( $instance ) { return isset( $instance['display_type'] ) ? $instance['display_type'] : 'list'; } public function widget( $args, $instance ) { if ( ! is_shop() && ! is_product_taxonomy() ) { return; } $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $taxonomy = $this->get_instance_taxonomy( $instance ); $query_type = $this->get_instance_query_type( $instance ); $display_type = $this->get_instance_display_type( $instance ); $enable_collapse = isset($instance['enable_collapse']) ? $instance['enable_collapse'] : $this->settings['enable_collapse']['std']; if ( ! taxonomy_exists( $taxonomy ) ) { return; } $terms = get_terms( $taxonomy, array( 'hide_empty' => '1' ) ); if ( 0 === count( $terms ) ) { return; } if( $enable_collapse != '0') $args['before_title'] = '<h4 class="widget-title enable-collapse"><span>'; ob_start(); $this->widget_start( $args, $instance ); if ( 'dropdown' === $display_type ) { wp_enqueue_script( 'selectWoo' ); wp_enqueue_style( 'select2' ); $found = $this->layered_nav_dropdown( $terms, $taxonomy, $query_type ); } else { $found = $this->layered_nav_list( $terms, $taxonomy, $query_type, $instance ); } $this->widget_end( $args ); // 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 ( ! $found ) { ob_end_clean(); } else { echo ob_get_clean(); } } protected function get_current_taxonomy() { return is_tax() ? get_queried_object()->taxonomy : ''; } protected function get_current_term_id() { return absint( is_tax() ? get_queried_object()->term_id : 0 ); } protected function get_current_term_slug() { return absint( is_tax() ? get_queried_object()->slug : 0 ); } protected function layered_nav_dropdown( $terms, $taxonomy, $query_type ) { global $wp; $found = false; if ( $taxonomy !== $this->get_current_taxonomy() ) { $term_counts = $this->get_filtered_term_product_counts( wp_list_pluck( $terms, 'term_id' ), $taxonomy, $query_type ); $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $taxonomy_filter_name = wc_attribute_taxonomy_slug( $taxonomy ); $taxonomy_label = wc_attribute_label( $taxonomy ); /* translators: %s: taxonomy name */ $any_label = apply_filters( 'woocommerce_layered_nav_any_label', sprintf( esc_html__( 'Any %s', 'plexify' ), $taxonomy_label ), $taxonomy_label, $taxonomy ); $multiple = 'or' === $query_type; $current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array(); $form_action = $this->get_current_page_url(); $form_action = remove_query_arg( [ 'query_type_' . $taxonomy_filter_name, 'filter_' . $taxonomy_filter_name, ], $form_action ); ?> <form method="get" action="<?php echo esc_url( $form_action ); ?>" class="pxl-wc-layered-nav-dropdown"> <select data-placeholder="<?php echo esc_attr( $any_label ); ?>" name="<?php echo 'filter_' . esc_attr( $taxonomy_filter_name ); ?>" class="pxl-layered-nav-dropdown pxl-dropdown_layered_nav_<?php echo esc_attr( $taxonomy_filter_name ); ?>" <?php echo esc_attr($multiple) == true ? ' multiple="multiple"' : ''; ?>> <option value=""><?php echo esc_html( $any_label ); ?></option> <?php foreach ( $terms as $term ) { // If on a term page, skip that term in widget list. if ( $term->term_id === $this->get_current_term_id() ) { continue; } // Get count based on current view. $option_is_set = in_array( $term->slug, $current_values, true ); $count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0; // Only show options with count > 0. if ( 0 < $count ) { $found = true; } elseif ( 0 === $count && ! $option_is_set ) { continue; } echo '<option value="' . esc_attr( urldecode( $term->slug ) ) . '" ' . selected( $option_is_set, true, false ) . '>' . esc_html( $term->name ) . '</option>'; } ?> </select> <?php if ( 'or' === $query_type ) : ?> <input type="hidden" name="query_type_<?php echo esc_attr( $taxonomy_filter_name ); ?>" value="or" class="filter-query-type"/> <?php endif; ?> </form> <?php } return $found; } protected function get_filtered_term_product_counts( $term_ids, $taxonomy, $query_type ) { return wc_get_container()->get( Filterer::class )->get_filtered_term_product_counts( $term_ids, $taxonomy, $query_type ); } protected function get_main_tax_query() { return WC_Query::get_main_tax_query(); } protected function get_main_search_query_sql() { return WC_Query::get_main_search_query_sql(); } protected function get_main_meta_query() { return WC_Query::get_main_meta_query(); } protected function layered_nav_list( $terms, $taxonomy, $query_type, $instance ) { $show_labels = isset( $instance['show_labels'] ) ? $instance['show_labels'] : $this->settings['show_labels']['std']; $display_type = isset( $instance['display_type'] ) ? $instance['display_type'] : $this->settings['display_type']['std']; $list_style = isset( $instance['list_style'] ) ? $instance['list_style'] : $this->settings['list_style']['std']; $items_count = isset($instance['items_count']) ? $instance['items_count'] : $this->settings['items_count']['std']; $enable_scrollable = isset($instance['enable_scrollable']) ? $instance['enable_scrollable'] : $this->settings['enable_scrollable']['std']; $enable_load_more = isset($instance['enable_load_more']) ? $instance['enable_load_more'] : $this->settings['enable_load_more']['std']; $enable_collapse = isset($instance['enable_collapse']) ? $instance['enable_collapse'] : $this->settings['enable_collapse']['std']; $ul_class = 'woocommerce-widget-layered-nav-list'; $ul_class .= ' display-' . $display_type; $ul_class .= ' show-count-' . $items_count; $ul_class .= ' enable-scrollable-' . $enable_scrollable; $ul_class .= ' enable-loadmore-' . $enable_load_more; $ul_class .= ' enable-collapse-' . $enable_collapse; $ul_class .= ' ' . $taxonomy; $attr_id = wc_attribute_taxonomy_id_by_name( $taxonomy ); $attr_info = wc_get_attribute( $attr_id ); if ( in_array( $display_type, [ 'list', 'inline' ], true ) ) { if ( 'swatches' === $list_style ) { switch ( $attr_info->type ) { case 'color': $ul_class .= ' list-style-color'; break; case 'image': $ul_class .= ' list-style-image'; break; case 'text': default: $ul_class .= ' list-style-text'; break; } $ul_class .= ' show-label-'.$show_labels; } elseif ( 'checkbox' === $list_style ) { $ul_class .= ' list-style-checkbox'; } else { $ul_class .= ' list-style-' . $list_style; } } $ul_style = ''; if( isset($instance['scrollable_height']) && !empty($instance['scrollable_height']) && $enable_scrollable == '1'){ $scroll_height = strpos($instance['scrollable_height'], 'px') ? $instance['scrollable_height'] : $instance['scrollable_height'].'px'; $ul_style = 'style="max-height:'.$scroll_height.';"'; } echo '<div class="widget-content-inner">'; echo '<div class="' . $ul_class . '" '.$ul_style.'>'; $term_counts = $this->get_filtered_term_product_counts( wp_list_pluck( $terms, 'term_id' ), $taxonomy, $query_type ); $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $found = false; $base_link = $this->get_current_page_url(); foreach ( $terms as $term ) { $current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array(); $option_is_set = in_array( $term->slug, $current_values, true ); $count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0; // Skip the term for the current archive. if ( $this->get_current_term_id() === $term->term_id ) { continue; } // Only show options with count > 0. if ( 0 < $count ) { $found = true; } elseif ( 0 === $count && ! $option_is_set ) { continue; } $filter_name = 'filter_' . wc_attribute_taxonomy_slug( $taxonomy ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); $current_filter = array_map( 'sanitize_title', $current_filter ); if ( ! in_array( $term->slug, $current_filter, true ) ) { $current_filter[] = $term->slug; } $link = remove_query_arg( $filter_name, $base_link ); // Add current filters to URL. foreach ( $current_filter as $key => $value ) { // Exclude query arg for current term archive term. if ( $value === $this->get_current_term_slug() ) { unset( $current_filter[ $key ] ); } // Exclude self so filter can be unset on click. if ( $option_is_set && $value === $term->slug ) { unset( $current_filter[ $key ] ); } } if ( ! empty( $current_filter ) ) { asort( $current_filter ); $link = add_query_arg( $filter_name, implode( ',', $current_filter ), $link ); // Add Query type Arg to URL. if ( 'or' === $query_type && ! ( 1 === count( $current_filter ) && $option_is_set ) ) { $link = add_query_arg( 'query_type_' . wc_attribute_taxonomy_slug( $taxonomy ), 'or', $link ); } $link = str_replace( '%2C', ',', $link ); } $item_link_class = 'filter-link term-link'; $swatch_span = $tooltip_span =''; if ( 'swatches' === $list_style ) : switch ( $attr_info->type ) : case 'color': $color = get_term_meta( $term->term_id, 'wpcvs_color', true ) ? : '#fff'; $tooltip_text = get_term_meta( $term->term_id, 'wpcvs_tooltip', true ) ? : ''; $item_link_class .= ' pxl-ttip tt-top'; $swatch_span = '<div class="term-color"><span style="background: ' . $color . '"></span></div>'; $tooltip_span = '<span class="tt-txt">'.$tooltip_text.'</span>'; break; case 'image': $val = get_term_meta( $term->term_id, 'wpcvs_image', true ); $tooltip_text = get_term_meta( $term->term_id, 'wpcvs_tooltip', true ) ? : ''; $item_link_class .= ' pxl-ttip tt-top'; $tooltip_span = '<span class="tt-txt">'.$tooltip_text.'</span>'; if ( ! empty( $val ) ) { $image_url = wp_get_attachment_thumb_url( $val ); } else { $image_url = wc_placeholder_img_src(); } $swatch_span = '<div class="term-shape"><span style="background-image: url(' . esc_attr( $image_url ) . ');"></span></div>'; break; case 'text': default: break; endswitch; endif; if ( 'checkbox' === $list_style && $attr_info->type == 'color') : $color = get_term_meta( $term->term_id, 'wpcvs_color', true ) ? : '#fff'; $swatch_span = '<span class="term-color" style="background: ' . $color . '"></span>'; endif; $count_html = ''; if ( 'on' === $items_count ) { $count_html = ' ' . apply_filters( 'woocommerce_layered_nav_count', '<span class="count">(' . absint( $count ) . ')</span>', $count, $term ); } if ( $count > 0 || $option_is_set ) { $link = apply_filters( 'woocommerce_layered_nav_link', $link, $term, $taxonomy ); $term_html = '<a rel="nofollow" href="' . esc_url( $link ) . '" class="' . esc_attr( $item_link_class ) . '">'.$tooltip_span.$swatch_span.'<span class="title">' . esc_html( $term->name ) . '</span>'.$count_html.'</a>'; } else { $link = false; $term_html = '<div>' . $swatch_span .'<span class="title">' . esc_html( $term->name ) . '</span>'. $count_html.'</div>'; } echo '<div class="woocommerce-widget-layered-nav-list__item wc-layered-nav-term ' . ( $option_is_set ? 'woocommerce-widget-layered-nav-list__item--chosen chosen' : '' ) . '">'; echo apply_filters( 'pxl_wc_layered_nav_term_html', $term_html, $term, $link, $count ); echo '</div>'; } echo '</div>'; $items_loadmore_display = (int)$instance['items_loadmore_display']; if( $enable_load_more == '1' && count($term_counts) > $items_loadmore_display){ echo '<span class="pxl-toogle-more" data-display="'.esc_attr($items_loadmore_display).'" data-less="'.esc_attr__( 'Less', 'plexify' ).'" data-more="'.esc_attr__( 'More', 'plexify' ).'" ><span class="text">' . esc_html__( 'More', 'plexify' ) . '</span><span class="pxl-icon pxli-angle-down2"></span></span>'; } echo '</div>'; return $found; } }
Submit
FILE
FOLDER
Name
Size
Permission
Action
author-info.php
20534 bytes
0644
product-layered-nav.php
17783 bytes
0644
recent-posts.php
8500 bytes
0644
widget-categories.php
6388 bytes
0644
N4ST4R_ID | Naxtarrr