Front-end filter logic

This topic contains 8 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 year ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #34395
    willfaulds59
    willfaulds59
    Participant

    Setup as attached.

    I cannot get the “All of the selected terms must match, exclude unselected (default)” to work as expected.

    Setup on WooCommerce products using product_tag taxonomy.

    Attachments:
    You must be logged in to view attached files.
    #34397
    willfaulds59
    willfaulds59
    Participant

    On the Front-End the filters appear as expected.

    A single product tagged with TagA, TagB and TagC will however only show when all 3 tags are selected.

    I have tried multiple combinations of settings but cannot find the correct settings so that:

    TagA selected = only product with TagA are results (ignore other tags).
    TagA and TagB selected = only product with TagA AND TagB are results (ignore other tags).

    • This reply was modified 1 year, 1 month ago by willfaulds59 willfaulds59.
    #34408
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Change this option: https://i.imgur.com/Y7Be135.png
    By default the unchecked checkboxes are treated as exclusions. This should resolve that.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #34415
    willfaulds59
    willfaulds59
    Participant

    Thank you Ernest,

    This still doesn’t quite give the behaviour I am looking for.

    TagA selected = only product with TagA are results (ignore other tags).
    TagA and TagB selected = only products with TagA AND TagB are results (ignore other tags).

    The settings you suggest give

    TagA and TagB selected = any products with TagA or TabB are results

    #34416
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Can you try the third option from that same drop-down? It should be very close to your requirements.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #34419
    willfaulds59
    willfaulds59
    Participant

    Thank you Ernest!

    I swore I had checked that option… but it does seem to be working as I wanted. Perfect.

    I have a last question about the theme chooser.
    https://documentation.ajaxsearchpro.com/theme-options/theme-chooser

    The documentation states you can use it without choosing a theme but I cannot seem to unload the previously selected theme.
    If as in the attached screenshot I choose “Select” the previous theme is still loaded

    Attachments:
    You must be logged in to view attached files.
    #34434
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Great 🙂

    It was phrased incorrectly in the documentation, I will correct that. By that we meant, that you can make changes to the initial layout (which is by default the “Simple red vertical” theme). The theme chooser is a baseline of pre-defined layouts, which you can load and then customize basically.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #34474
    willfaulds59
    willfaulds59
    Participant

    Good to know, thank you Ernest.

    I would love to see a future option of a very VERY bare-bones theme for easy integration with other/custom themes.

    I am now working on adding a radio front-end filter for some product tags that are cannot exist on the same product. e.g. Alcoholic and Non-alcoholic. I can’t quite get the code to work.

    I have 2 hopefully simple questions

    1/ Can I add a filter to appear within an existing fieldset? E.g. underneath “Filter by Product tags” created in the admin back-end?
    2/ Can you help correct the below example to correctly search with product_tag

    Many thanks,

    Would you be interested in WooCommerce related write-ups and snippets when this project is complete?

    //from: https://knowledgebase.ajaxsearchpro.com/frontend-filters/frontend-filters-api
    add_action('asp_pre_parse_filters', 'asp_add_my_own_filters', 10, 2);
    function asp_add_my_own_filters($search_id, $options) {
        if ( $search_id == 1 ) {
            // Radio
    		
    		/*
    		$type (string) - The filter type, can be: taxonomy
    		$label (string) (optional) - The filter box header label
    		$display_mode (string) (optional) - The display mode of the filter values: checkboxes, input, slider, range, dropdown, radio, dropdownsearch, multisearch
    		$data (array) (optional) - Additional data, that may be required within the template for this filter depending on the $type and $display_mode
    		Check the examples below for the usage.
    		*/
    		
            $filter = wd_asp()->front_filters->create(
                'taxonomy',
                null,//'Filter testing'
                // Type: dropdown, dropdownsearch, multisearch or radio
                'radio',
                array(
                    'taxonomy' => 'product_tag',
                )
            );
            $filter->add(array(
                'label' => 'Alcoholic',
    			'taxonomy' => 'product_tag',
                'id' => '21',//tag_id stupid no the the slug
                'selected' => false,
            ));
            $filter->add(array(
                'label' => 'Non-alcoholic',
    			'taxonomy' => 'product_tag',
                'id' => '22',//tag_id stupid no the the slug
                'selected' => false,
            ));
            $filter->selectByOptions($options);
            wd_asp()->front_filters->add($filter);
        }
    }
    #34490
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    To add new values to an existing taxonomy term filter, use this one:

    add_filter('asp_pre_get_front_filters', 'asp_change_a_filter', 10, 2);
    function asp_change_a_filter($filters, $type) {
    	foreach ($filters as $k => &$filter) {
    		if ( $filter->field() == 'product_tag' ) {
    			$filter->add(array(
    			  'label' => 'My custom product tag',
    			  'selected' => false,
    			  'id' => 123
    			));
    		}
    	}
    	return $filters;
    }

    Of course the tag ID needs to be an existing tag ID, the label does not matter.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.