I have set it up how it should work, but, in your shop page, the grid is a special, non-WooCommerce grid, that does not use WooCommerce classes and uses Masonry.
As such, when a search is made, it correctly now goes to the page, and reports the correct number of posts, but they are hidden with opacity set to 0, and the masonry script does not re-trigger. If you switch Ajax off, then it should work. This is not unusual for masonry. Is there a way to make this grid non-Masonry? I can see it is made with a shortcode ([products]) which doesn’t seem to have any options. Maybe the options are in your theme?
AnonymousInactive
Hi Trevor,
Thanks for the fast response.
So the pagination doesn’t actually work with Ajax disabled either. If I take the below code out of the code though, it does.
do_action("search_filter_query_posts", 65646);
With the ‘woocommerce – shop’ method the pagination + Ajax does work correctly. This makes me think it’s not an issue with the css selectors and maybe the way it’s implementing the filter into the query?
It looks OK, but I would have set the Ajax Container to .products and the pagination container to .woocommerce-pagination a
A good test is to disable Ajax. Does it work then? If it does, then it may just be these settings.
Ok great, I’ve put comments in the code so put in you text editor and read through (this should go in your themes functions.php) – let me know if any questions:
//restrict the results to a specific product attribute, by attibute ID
add_filter('sf_apply_custom_filter', 'sf_woocommerce_filter_by_attribute', 12, 3);
function sf_woocommerce_filter_by_attribute($ids_array, $query_args, $sfid) {
// this is the ID of the search form we want to apply the include on, change 123456 to your search form ID
if($sfid===123456){
$field_name = "_sft_pa_perro-gato"; //the S&F name for the field - I think this is correct for your setup
// here, you need to check, are we on Pero attribute, or are we on Gato attribute,
// then set $field_value accordingly
$field_value = 999; //the ID of your product attribute that you want to "restrict" the results to
// --- thats it, leave the rest of the code in tact
//get the visibility IDs directly from S&F tables
$merge = true;
if(isset($ids_array[0])) {
if ( $ids_array[0] === false ) {
$merge = false;
}
}
global $wpdb;
$term_results_table_name = $wpdb->prefix . 'search_filter_term_results';
$field_terms_results = $wpdb->get_results(
"
SELECT field_name, field_value, result_ids
FROM $term_results_table_name
WHERE field_name = '$field_name'
AND field_value = '$field_value' LIMIT 0, 1
"
);
if((count($field_terms_results)==1) && (property_exists($field_terms_results[0], 'result_ids'))) {
$ids = explode(',', $field_terms_results[0]->result_ids);
if ( $merge == false ) {
$ids_array = $ids;
} else {
$ids_array = array_intersect( $ids_array, $ids );
}
}
}
return $ids_array;
}
AnonymousInactive
Hi Ross, the problem is not on search result, tahs is fine. Is on the form fields options.
For example:
Focus on first filter field: “Razas” (dog race)
We have some variations with atribute “Perro maxi (+25 Kg)”.
Please select this option.
Now, field number two, “Edades” (age) have to display here only atributes options of products and variation that coincide with the first field.
In this case, only show one option (7 años, 7 years), but there are a lot more. For example, if you go to woocommerce -> atributes select Raza, can see that “Perro maxi (+25 Kg)” have 13 products associated. If you check some, can see there are more variations with “Perro maxi (+25 Kg)” and othes age atributes that the filter don’t show, like “+ 24 meses”, ….
Thanks!
WooCommerce Product ‘Categories’ and ‘Tags’ are normally a ‘custom’ Taxonomy, and not ‘Category’ or ‘Tag’. So, add a ‘Taxonomy’ for each to the form and select them from the dropdown select list of taxonomies:
https://www.screencast.com/t/SAFs55DzT
AnonymousInactive
Main issues:
-Categories not showing up
-Tags not showing up
Info:
I’m using Elementor Pro and Woocommerce.
AnonymousInactive
The page is using woocommerce.php template. I saw that problem too but <?php woocommerce_content(); ?> is the one that’s getting the pagination… I also tried with Custom (not woocommerce) and shortcode setting and have the same problem. I will take a look on my woocommerce child theme, maybe the problem is there.
The thing is that is not only the pagination my problem, can you test when you combine the two taxonomy filters? I have also problems with that and the sorting filter…
thanks a lot Trevor
AnonymousInactive
Hi,
I bought the plugin yesterday and noticed that the CSS is lost when any of filters are clicked. However when I hit refresh on the browser, the CSS comes back. I checked the CSS, the Style2 tags go missing, and they come back when browser is refreshed. This happens on every filter click irrespective of whether it is a Radio Checkbox or Combo.
Could you help me to understand what could be causing this.
My setup is as follows:
Woocommerce
Grid modification plugin – None
Location – localhost
Filter defined using Taxonomies
Load results using Ajax? – Checked
Make searches bookmarkable – Checked
Use only Ajax on the results page – Unchecked (Tried also with Checked)
Load JavaScript & CSS files – Checked
Lazy Load JavaScript – Unchecked
Combobox Script – Select2
Load jQuery UI i18n files – Unchecked
Auto submit form – Checked
Enabled Auto Count – Checked
Update the Search Form on user interaction – Checked
Also I rewrote the WordPress Default Search form using this script from the Support Forum
function sandf_change_search_url_rewrite() {
if ( is_search() && ! empty( $_GET[‘s’] ) ) {
wp_redirect( home_url( “products/?_sf_s=” ) . urlencode( get_query_var( ‘s’ ) ) );
exit();
}
}
add_action( ‘template_redirect’, ‘sandf_change_search_url_rewrite’ );
OK, before I ask our developer to take a look, can you make a test form and see if you can set this to the WooCommerce method and place the form somewhere on the shop page and see if it works that way?