Hiding products without image
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page pleaseIf you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.
Quote from selonya on December 26, 2024, 10:20I found these hooks here:
https://products-filter.com/hook?page=3
I tried to change the one that tampers with the search SQL query before executing the query to fit my need.
But it seems like no matter what I write there it has no effect on the results.
Here's the link to the website: https://www.selonya.com/products/swoof/product_cat-ranforce/
And here's the code I'm trying right now:
add_filter('woof_text_search_query', function($where, $woof_text) { global $wpdb; $where = " INNER JOIN wp_postmeta AS m ON $wpdb->posts.ID = m.post_id " . $where; $where .= " AND m._thumbnail_id IS NOT NULL "; return $where; }, 99, 2);Any ideas how to make it work? Thanks,
(I'm trying to hide the products that have no image in the ajax search filter results)
-Amin
I found these hooks here:
https://products-filter.com/hook?page=3
I tried to change the one that tampers with the search SQL query before executing the query to fit my need.
But it seems like no matter what I write there it has no effect on the results.
Here's the link to the website: https://www.selonya.com/products/swoof/product_cat-ranforce/
And here's the code I'm trying right now:
add_filter('woof_text_search_query', function($where, $woof_text) { global $wpdb; $where =" INNER JOIN wp_postmeta AS m ON $wpdb->posts.ID = m.post_id" . $where; $where .=" AND m._thumbnail_id IS NOT NULL"; return $where; }, 99, 2);
Any ideas how to make it work? Thanks,
(I'm trying to hide the products that have no image in the ajax search filter results)
-Amin
Quote from Pablo Borysenco on December 26, 2024, 11:57Hello Amin
You should hire a developer to implement this customization.
This code will not work
Try to use these standard hooks - posts_join posts_where
Hello Amin
You should hire a developer to implement this customization.
This code will not work
Try to use these standard hooks - posts_join posts_where
Quote from selonya on December 26, 2024, 13:11Thanks for the reply.
Well, I'm the "developer", lol.
Okay then I should increase my knowledge from MySQL.
But it seems like no matter what put in the plugin's hook it doesn't become effective. As if it was dropped in the development of the plugin.
Using Wordpress hooks is not useful here, because the HUSKY plugin usese ajax to search for products. We need to stick with the plugin's hooks... if there's a working one.
Thanks for the reply.
Well, I'm the"developer", lol.
Okay then I should increase my knowledge from MySQL.
But it seems like no matter what put in the plugin's hook it doesn't become effective. As if it was dropped in the development of the plugin.
Using Wordpress hooks is not useful here, because the HUSKY plugin usese ajax to search for products. We need to stick with the plugin's hooks... if there's a working one.
Quote from Pablo Borysenco on December 27, 2024, 11:04Hello
I apologize for this.
1 woof_text_search_query - you can't add JOIN because it's for WHERE. so this code will always throw a SQL syntax error
2 + in the new version of the text filter this hook is not used
3 posts_join posts_where - These hooks are used for all WP_Query queries. Even if this request is made in ajax mode
To check if this query is a text search:
if (!isset($wp_query->query_vars['woof_text_filter']) && !isset($wp_query->query_vars['woof_text_filter'])) {
return $join;
}If you enable filtering by SKU or filtering by custom fields in the text filter settings, then the filter itself will add a JOIN for meta data. In this case you don't need to use the hook - posts_join. and then the metadata table will have an alias: postmeta
In this case, you can only use one hook - posts_where ( Warning! This is a sample code without checks. This code shows the concept of the solution and may contain errors. )
add_filter('posts_where', function($where, $wp_query ){
// Is this really a text search for products?
if (isset($wp_query->query_vars['post_type']) && ('product' == $wp_query->query_vars['post_type'] || (is_array($wp_query->query_vars['post_type']) && in_array('product', $wp_query->query_vars['post_type'])) )) {
if (!isset($wp_query->query_vars['woof_text_filter']) && !isset($wp_query->query_vars['woof_text_filter'])) {
return $where;
}$where .= " AND ( postmeta.meta_key = '_thumbnail_id' AND postmeta.meta_value IS NOT NULL)";
}
return $where;}, 30, 2);
Hello
I apologize for this.
1 woof_text_search_query - you can't add JOIN because it's for WHERE. so this code will always throw a SQL syntax error
2 + in the new version of the text filter this hook is not used
3 posts_join posts_where - These hooks are used for all WP_Query queries. Even if this request is made in ajax mode
To check if this query is a text search:
if (!isset($wp_query->query_vars['woof_text_filter']) && !isset($wp_query->query_vars['woof_text_filter'])) {
return $join;
}
If you enable filtering by SKU or filtering by custom fields in the text filter settings, then the filter itself will add a JOIN for meta data. In this case you don't need to use the hook - posts_join. and then the metadata table will have an alias: postmeta
In this case, you can only use one hook - posts_where ( Warning! This is a sample code without checks. This code shows the concept of the solution and may contain errors. )
add_filter('posts_where', function($where, $wp_query ){
// Is this really a text search for products?
if (isset($wp_query->query_vars['post_type']) && ('product' == $wp_query->query_vars['post_type'] || (is_array($wp_query->query_vars['post_type']) && in_array('product', $wp_query->query_vars['post_type'])) )) {
if (!isset($wp_query->query_vars['woof_text_filter']) && !isset($wp_query->query_vars['woof_text_filter'])) {
return $where;
}
$where .=" AND ( postmeta.meta_key = '_thumbnail_id' AND postmeta.meta_value IS NOT NULL)";
}
return $where;
}, 30, 2);
Quote from selonya on December 27, 2024, 17:09Thanks!
I tried it, and it didn't hide the no-image products using json in pages 2-3....
I will work on it later on and once I get results will write the code here.
Best,
Thanks!
I tried it, and it didn't hide the no-image products using json in pages 2-3....
I will work on it later on and once I get results will write the code here.
Best,
Quote from Pablo Borysenco on December 30, 2024, 11:11Ok! Welcome;)
Ok! Welcome;)
Quote from selonya on December 30, 2024, 16:56Here's the code that works... at least for me:
(I used your first condition to check if it's a product, but your second condition returned true all the time, that's why it didn't work. So I dropped it.)
add_filter('posts_where', function($where, $wp_query ){ global $wpdb; // Is this really a text search for products? if (isset($wp_query->query_vars['post_type']) && ('product' == $wp_query->query_vars['post_type'] || (is_array($wp_query->query_vars['post_type']) && in_array('product', $wp_query->query_vars['post_type'])))) { $where .= " AND EXISTS ( SELECT 1 FROM {$wpdb->postmeta} pm WHERE pm.post_id = {$wpdb->posts}.ID AND pm.meta_key = '_thumbnail_id' AND pm.meta_value IS NOT NULL )"; } return $where; }, 30, 2);
Here's the code that works... at least for me:
(I used your first condition to check if it's a product, but your second condition returned true all the time, that's why it didn't work. So I dropped it.)
add_filter('posts_where', function($where, $wp_query ){ global $wpdb; // Is this really a text search for products? if (isset($wp_query->query_vars['post_type']) && ('product' == $wp_query->query_vars['post_type'] || (is_array($wp_query->query_vars['post_type']) && in_array('product', $wp_query->query_vars['post_type'])))) { $where .=" AND EXISTS ( SELECT 1 FROM {$wpdb->postmeta} pm WHERE pm.post_id = {$wpdb->posts}.ID AND pm.meta_key = '_thumbnail_id' AND pm.meta_value IS NOT NULL )"; } return $where; }, 30, 2);
Quote from Pablo Borysenco on December 31, 2024, 10:21Hello
Great! Thank you for your cooperation!
Hello
Great! Thank you for your cooperation!