Forum Replies Created
-
AuthorPosts
-
willfaulds59
ParticipantThanks Ernest,
One last addon before it closes…
Some reasonably robust (perhaps you can suggest a better solution than using the ‘click’ event) and commented javascript for making filters act like toggles (in this case ONLY one can be one at a time, but both can be off, so NOT a true toggle).

jQuery(window).ready(function($) { function linkASPFrontendFilterEvent( $master, $slave ){ $master.on('click', function () {//must be ASP js that prevents 'change' working (even if override the input being hidden) if( jQuery(this).find('input[type=checkbox]').is(':checked') ) {//must be ASP js that prevents .checked working $slave.find('input[type=checkbox]').prop( "checked", false ); } }); } function linkASPFrontendFilter( term1, term2 ){ if( jQuery( '.'+term1) !== null && jQuery( '.'+term2) !== null ){ var $elem1 = jQuery( '.asp_option.'+term1 ); var $elem2 = jQuery( '.asp_option.'+term2 ); linkASPFrontendFilterEvent( $elem1, $elem2 ); linkASPFrontendFilterEvent( $elem2, $elem1 ); }; }; //array toggle classes to be linked (Requires a theme override e.g. asp-tax-checkboxes.php with "str_replace(' ', '-', strtolower(strip_tags($term->label))); ?> ") const ao_asp_toggles = [ ['alcoholic','non-alcoholic'], ['sparkling','still'], ]; //loop through the classes for (i = 0; i < ao_asp_toggles.length; ++i) { linkASPFrontendFilter( ao_asp_toggles[i][0], ao_asp_toggles[i][1] ); }; });-
This reply was modified 4 years, 6 months ago by
willfaulds59.
-
This reply was modified 4 years, 6 months ago by
willfaulds59.
-
This reply was modified 4 years, 6 months ago by
willfaulds59.
-
This reply was modified 4 years, 6 months ago by
willfaulds59.
willfaulds59
ParticipantExcellent! Thank you.
Posting to help others in the future
add_filter( 'asp_fontend_get_taxonomy_terms', 'asp_reorder_terms', 1, 3 ); function asp_reorder_terms($terms, $taxonomy, $args) { if ( $taxonomy == 'product_tag' ) {//'product_tag' is for WooCommerce $custom_order = [ 'slug2' , 'slug3' , 'slug4' , 'slug1' ];//desired order of terms using their slug $terms_reordered = []; $i = 0; foreach($custom_order as $slug => $data){ foreach($terms as $term){ if($term->slug == $slug){ $terms_reordered[$i] = $term; unset($term);//unset so mark it reordered } } $i++; } return array_merge($terms_reordered, $terms);//merge in any terms not reordered } return $terms; }-
This reply was modified 4 years, 6 months ago by
willfaulds59.
willfaulds59
ParticipantThanks for you’re help finding a working solution to passing a custom variable I have a reliable solution now.
The missing results seemed to be a weird behaviour of WooCommerce variable product types and was not specific to ASP.
willfaulds59
ParticipantI have noticed some missing results elsewhere so I’m going to debug the issue today and see if its being caused by a modification/override/plugin.
willfaulds59
ParticipantYou cannot access this content.
willfaulds59
ParticipantThank you Ernest, after debugging for a while I have found why I thought the post_in did not work for WooCommerce products.
When
$args['post_in']is set the AJAX call to admin-ajax.php response does not contain any HTML – its a data JSON only. I will copy into a private reply the Headers and Response from Chrome Dev tools.-
This reply was modified 4 years, 7 months ago by
willfaulds59.
-
This reply was modified 4 years, 7 months ago by
willfaulds59.
-
This reply was modified 4 years, 7 months ago by
willfaulds59.
willfaulds59
ParticipantAha, yes that’s a good solution to passing the variables.
Do you have a recommendation for a similar functionality to the post_in arg for Woocommerce products?
willfaulds59
ParticipantAnother dead end 🙁
add_filter("asp_query_args", "asp_query_args_change", 10, 2); function asp_query_args_change($args, $search_id) { //WORKAROUND:set a search term? // $args[s]=searchterm // &asp_s='+encodeURIComponent('related_items:') // &asp_s=related_items%3A //as this is loaded via AJAX I cannot access the query string, $_REQUEST doesn't hold the referer URL either :( if($args['s']) { $searchterm = $args['s']; if ( strpos( $searchterm, 'related_items:' ) !== false) { $id_string = str_replace('related_items:', '', $searchterm); $ids = explode(',',$id_string); $args['post_in'] = array_unique( $ids ); $args['s']=''; } } //TODO stop the search term showing in search box return $args; }I thought I had a great workaround but unfortunately the $args[‘post_in’] seems to only apply to standard WP posts?
Any better solutions/imporvements for WC products?
willfaulds59
ParticipantI can see a potential method… but can’t get it working.
The $_REQUEST [options] contains some of the query string.
I have tried registering a custom query variable
add_filter( 'query_vars', 'add_query_vars_filter' ); function add_query_vars_filter( $vars ){ $vars[] = 'custom_var'; return $vars; }but ASP but not pass it to the asp_query_args filter/AJAX call
I have tried adding a custom ASP front-end filter
add_action('asp_pre_parse_filters', 'asp_add_my_own_filters', 10, 2); function asp_add_my_own_filters($search_id, $options) { $filter = wd_asp()->front_filters->create( 'custom_field', 'Text stock', // text or hidden 'text', array( 'field' => '_stock_status', // See operator list on above example 'operator' => 'eq' ) ); $filter->add(array( 'label' => 'Stock status', 'value' => 'instock', 'default' => 'instock' )); $filter->selectByOptions($options); wd_asp()->front_filters->add($filter); }but I cannot override this via the query string…
Any ideas as to a viable solution?
-
This reply was modified 4 years, 7 months ago by
willfaulds59.
willfaulds59
ParticipantGood 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_tagMany 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); } }-
This reply was modified 4 years, 9 months ago by
willfaulds59.
-
This reply was modified 4 years, 9 months ago by
willfaulds59.
willfaulds59
ParticipantThank 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-chooserThe 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 loadedwillfaulds59
ParticipantThank 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
willfaulds59
ParticipantOn 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 4 years, 9 months ago by
willfaulds59.
willfaulds59
ParticipantExcellent!
This has worked perfectly.
-
This reply was modified 4 years, 6 months ago by
-
AuthorPosts