Home / Forums / WoodMart support forum / Customize filter for adding new function
Home › Forums › WoodMart support forum › Customize filter for adding new function
Customize filter for adding new function
- This topic has 6 replies, 2 voices, and was last updated 5 years, 11 months ago by
Artem Temos.
-
AuthorPosts
-
July 22, 2020 at 9:35 am #213108
cmadvisorParticipantHello,
this is the 7th site with your theme and i need to customize filter type in Elementor with adding just 1 level of “Categories”, not ancestors. So, for now i’ve found the file “class-product-filters.php” in “Elements” of integrations and started customization. I’ve opened this topic for 2 reasons:1) I think can is a new amazing features can u add to your amazing theme;
2) I need some help with finish my customization, if u can…So, i’ve found the function and on line 132 i’ve customized the code:
$repeater->add_control( 'filter_type', [ 'label' => esc_html__( 'Filter type', 'woodmart' ), 'type' => Controls_Manager::SELECT, 'options' => [ MY CUSTOMIZATION----> 'sono' => esc_html__( 'Sono' ), 'categories' => esc_html__( 'Categories', 'woodmart' ), 'attributes' => esc_html__( 'Attributes', 'woodmart' ), 'stock' => esc_html__( 'Stock status', 'woodmart' ), 'price' => esc_html__( 'Price', 'woodmart' ), ], 'default' => 'categories', ] ); /** * MY CUSTOMIZATION "Sono settings". I use your code for autocomplete, so integrated with your existing function. */ $repeater->add_control( 'sono', [ 'label' => esc_html__( 'Categories', 'woodmart' ), 'description' => esc_html__( 'List of product categories.', 'woodmart' ), 'type' => 'wd_autocomplete', 'search' => 'woodmart_get_taxonomies_by_query', 'render' => 'woodmart_get_taxonomies_title_by_id', 'taxonomy' => 'product_cat', 'multiple' => true, 'label_block' => true, 'condition' => [ 'filter_type' => 'sono', ], ] );For now, no problem. But for add really my function and show my customization, i need to change on line 401:
/** * Repeater settings. */ $this->add_control( 'items', [ 'type' => Controls_Manager::REPEATER, 'title_field' => '{{{ filter_type }}}', 'fields' => array_values( $repeater->get_controls() ), 'default' => [ [ MY CUSTOMIZATION-----> 'filter_type' => 'sono' ], [ 'filter_type' => 'categories', ], [ 'filter_type' => 'attributes', ], [ 'filter_type' => 'stock', ], [ 'filter_type' => 'price', ], ], ] );And on line 515:
<form <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>> <?php foreach ( $settings['items'] as $index => $item ) : ?> <?php if ( 'categories' === $item['filter_type'] ) : ?> <?php $this->categories_filter_template( $item ); ?> MY CUSTOMIZATION----> <?php elseif ( 'sono' === $item['filter_type'] ) : ?> <?php $this->sono_filter_template( $item ); ?> <?php elseif ( 'attributes' === $item['filter_type'] ) : ?> <?php $this->attributes_filter_template( $item ); ?> <?php elseif ( 'stock' === $item['filter_type'] ) : ?> <?php $this->stock_filter_template( $item ); ?> <?php elseif ( 'price' === $item['filter_type'] ) : ?> <?php $this->price_filter_template( $item ); ?> <?php endif; ?> <?php endforeach; ?> <div class="woodmart-pf-btn"> <button type="submit"> <?php esc_html_e( 'Filter', 'woodmart' ); ?> </button> </div> </form> <?php }And for show on frontend, on line 538 i’ve added my public_function:
public function sono_filter_template( $settings) { $default_settings = [ // Query. 'sono_title' => esc_html__( 'Sono...', 'woodmart' ), 'number' => null, 'orderby' => '', 'order' => 'ASC', 'ids' => '', 'show_categories' => '', ]; $settings = wp_parse_args( $this->get_settings_for_display(), $default_settings ); // Query. $query_args = array( 'taxonomy' => 'product_cat', 'order' => $settings['order'], 'include' => $settings['ids'], 'pad_counts' => true, 'number' => $settings['number'], ); if ( $settings['orderby'] ) { $query_args['orderby'] = $settings['orderby']; } $categories = get_terms( $query_args ); ?> <div class="woodmart-pf-checkboxes woodmart-pf-categories"> <div class="woodmart-pf-title"> <span class="title-text"> <?php echo esc_html( $settings['sono_title'] ); ?> </span> <ul class="woodmart-pf-results"></ul> </div> <div class="woodmart-pf-dropdown woodmart-scroll"> <ul class="woodmart-scroll-content"> <?php if ( $settings['show_categories'] ) : ?> <li style="display:none;" class="pf-active cat-item cat-item-<?php echo $current_cat->term_id; ?>"> <a class="pf-value" href="<?php echo esc_url( get_category_link( $product_cat->term_id ) ); ?>" data-val="<?php echo esc_attr( $current_cat->slug ); ?>" data-title="<?php echo esc_attr( $current_cat->name ); ?>"> <?php echo esc_html( $current_cat->name ); ?> </a> </li> <?php endif; ?> <?php echo wp_list_categories( $query_args ); ?> </ul> </div> </div> <?php }Now. My customization work for backend function, but in frontend i need for sure your help. I didn’t understood how i can change your $current_cat string with a cat choose in backend. How i can do that? Can u help me?
Attachments:
You must be logged in to view attached files.July 22, 2020 at 9:57 am #213119
cmadvisorParticipantUpdate:
I’ve changed my query_args for better UX in frontend, now i’ve added the “select” style of your theme. So, i’ve changed this:'taxonomy' => 'product_cat', 'order' => $settings['order'], 'include' => $settings['ids'], 'pad_counts' => true, 'number' => $settings['number'],With this:
'taxonomy' => 'product_cat', 'order' => $settings['order'], 'walker' => new WOODMART_Custom_Walker_Category(), 'include' => $settings['ids'], 'pad_counts' => true, 'number' => $settings['number'],July 22, 2020 at 11:26 am #213147Hello,
We don’t quite understand what your new filter should work. Please, explain what should your code do and what exactly do you need help with?
Regards
July 22, 2020 at 11:45 am #213153
cmadvisorParticipantHello,
For now your filters work with “ALL CATEGORIES” for select and filter.
I want add another filter can make “CHOOSE CATEGORIES” to select by ID and Search.
So, when add filter “categories”, i want choose one or more categories available to select.
For example:
I’ve “clothes” and “furniture” categories in my woocommerce, but in categories filter i want choose just “clothes” and not “furniture”.I need your help for complete my code with show what i select in backend.
July 22, 2020 at 12:57 pm #213186Sorry, but we don’t have an instruction for such customizations. Actually, WooCommerec doesn’t have a functionality to display products from multiple categories at the same time. It is possible only if you create some custom product attributes instead of categories.
July 22, 2020 at 3:47 pm #213253
cmadvisorParticipantHello,
no problem. I’ve solved with custom ids in “$query_args”:$query_args = array( 'taxonomy' => 'product_cat', 'title_li' => false, 'order' => $settings['order'], 'walker' => new WOODMART_Custom_Walker_Category(), HOW I CAN SOLVED ---> 'include' => array( '39', '40', '44', ), 'order_by' => 'id', 'pad_counts' => true, 'number' => $settings['number'], );So, all ids i want put in “include”, it show on frontend. I need now just put in an function with an if and i’ve done.
Thanks.Regard
July 23, 2020 at 7:14 am #213369Great, we are glad that you sorted it out!
-
AuthorPosts
Tagged: customization, filters
- You must be logged in to create new topics. Login / Register