Smart category to to show the product that contains some word in the Title
-
Hi Good people,
I try to find the way to configure, adjust the categorie sin that wey that I will be able to set the condition whta need to be shown in the category,
For example, I have imported lot of products to my store, I want to have few categories, for example:
Category name: Hair dryer
condition: show only products that contain “Hair drier” in the title.
This solution is quite the same as collection in Shopify.
Any advice, hints how to realize such functionality ?
I will be thankful
-
Hello @piotrpepson,
Thank you for reaching out!condition: show only products that contain “Hair drier” in the title.
Just to clarify, do you intend to display this on the category archive page itself? Wouldn’t it be easier to simply remove the product from the “Hair Dryer” category? :?)
Look forward to hearing back from you.but I need few categories that will contain specific products that contains specific product titles.
I have integration turned on, dynamically new products are added in the daily basis, and categories need to be smart, need to display product based on the criteria.
All the products contain specific product type name in the title, base on that category need to have criteria to be setup
category: shampoo
criteria: product title contain “shampoo”
Etc.
Hi @piotrpepson,
While WooCommerce doesn’t have this specific feature built-in, you can achieve this functionality with a bit of custom coding or using a plugin.
One plugin that might help is Import Export Suite for WooCommerce. It allows you to import products and assign them to categories based on certain conditions, such as the product title. You can set up a CSV file with your products and the corresponding categories based on the product titles and then import it using the plugin.
You might need to hire a developer to write a custom script for a more automated solution. The script would need to check the product title when a new product is added and assign it to the appropriate category based on the criteria you’ve set.
Please note that any customizations would be outside the scope of our support, and we recommend working with a WooCommerce expert to ensure everything is set up correctly.
I hope this clarifies your concern. If you have any other questions, feel free to ask.
Hi, Thank you or reply, this solution will not work, i have already implemented API import interface from Syncee.
Another idea that I have in my mind is the filtering option, directly on the category page. Is there any way to code or set up permanent filter (not visible for visitors) after clicking in the menu, client will see only the products that will contain in title special works
please let me know
Hi @piotrpepson,
Thanks for getting back to us. I understand you are looking to create smart categories based on product titles and automatically assign products to categories based on the keywords in their titles, like “Hair dryer” or “Shampoo”. This can be very useful for organizing your products and making them easier to find for your customers.
There are a few ways you can achieve this functionality in WooCommerce, depending on your preferences and needs. Here are some possible solutions you can try:
- Use a plugin like Smart Category for WooCommerce, which automatically suggests the best matching categories based on the product title. You can also use it to suggest brands or any other custom taxonomy. You can find more information on how to use this plugin here: Smart Category for WooCommerce
- Use the built-in product tags and attributes in WooCommerce, which act as keywords for your products. You can add tags and attributes to your products manually or in bulk, and then use them to filter and display products on your shop page. You can find more information on how to add tags and attributes here: How to Add Tags, Attributes, and Categories to WooCommerce
- You can try a plugin like WooCommerce Product Filter, which allows you to create advanced filters for your products based on any criteria, including title, price, category, tag, attribute, rating, and more. You can also use the plugin to create custom filters based on your own taxonomies, meta fields, or custom fields. This way, you can filter your products by any keyword or term that you want.
If you have any other questions or concerns, please feel free to contact us again. We are always happy to help. ??.
Hey there ??,
We haven’t heard back from you in a while, so I’m going to mark this as resolved – feel free to create a new topic if you need any further help. ??
Cheers!
probably some dev work need to be done, I need to have categories that shows products based on the title filter , anyone can refer some good dev to implement that solution ?
Hi @piotrpepson,
Thanks for getting back to us. I understand you need some custom development work done on your site. Unfortunately, custom coding is beyond the scope of our support. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. You can also seek help from the following:
- A local web developer who can work with you on your specific needs and budget.
- WooExperts are verified WooCommerce experts who offer full-service solutions. You can browse the WooExperts directory and filter by location, budget, and project type here: https://partners.woo.com/English/marketplace/
Hopefully, this gets you going in the right direction to get the job done.
Hi All,
I have found solution, its so easy. If your category is fulfilled by integrator and products are imported from external source, then if you want to have dynamic “smart” categories like in Shopify.
- Download the Snipes app for adding the code to function.php
- Rename you category that contains all products, example: “Shampoo for hair grow”
- Past below code to the Snipes app (create new code):
function custom_dynamic_category_query($query) {
// Sprawd?, czy jeste?my na stronie kategorii, dla której ma dzia?a? funkcja
if (is_product_category(‘twoja_wybrana_kategoria’)) {
// Dodaj warunek dla wyszukiwania s?owa w tytule produktu
$query->set(‘s’, ‘s?owo_do_wyszukania_w_tytule’);
}
}
add_action(‘pre_get_posts’, ‘custom_dynamic_category_query’);4. in the code -> change the name of the twoja_wybrana_kategoria’ to ‘Shampoo for hair grow’
5. in the code -> change the word that is in the poduct title ‘s?owo_do_wyszukania_w_tytule’ to ‘Shampoo for hair grow’
Activate the code, your ‘Shampoo for hair grow’ category will only shows product that have in title: “‘Shampoo for hair grow”
No need for hire developer, do it by your self ??
Hi @piotrpepson,
Thank you for sharing your solution with us and the WooCommerce community. I’m glad to know you were able to resolve the issue by using Snipes to add custom code to your function.php file.
Your feedback is valuable and helps us improve our products and services. We appreciate your time and effort in troubleshooting this issue and posting your findings on the forum.
Just so you know – we will now close this ticket as solved. If you have any other questions or issues, please feel free to open a new ticket and we’ll be happy to assist you.
Thank you for choosing WooCommerce and have a great day!
One remarks, codes work fine but there is one small issue.
After clicking in the category the menu star to display not he store category but some random page names see: screen shots.
- go to the address: https://trycho-medica.pl/sklep/
- click in the category: “Prostownice do w?osów”: https://trycho-medica.pl/kategoria-produktu/wszystkie-produkty/prostownice-do-wlosow/
any thoughts ?
code used:
function custom_dynamic_category_query($query) {
// check if the category is the one that need to be dynamically filtered
if (is_product_category(‘category_name’)) {
// Specific word in the product title
$query->set(‘s’, ‘word_in_product_title’);
}
}
add_action(‘pre_get_posts’, ‘custom_dynamic_category_query’);I have corrected the code with help of ChatGPT, now its work fine:
if (is_product_category(‘Prostownice do w?osów’)
was changed with:
if (is_product_category(‘Prostownice do w?osów’) && $query->is_main_query()) {
whole code:
function custom_dynamic_category_query($query) {
// Check if we are on the product category page and target a specific category
if (is_product_category(‘Prostownice do w?osów’) && $query->is_main_query()) {
// Specific word in the product title
$query->set(‘s’, ‘prostownica’);
}
}
add_action(‘pre_get_posts’, ‘custom_dynamic_category_query’);Hi @piotrpepson,
I’m happy to see that you have solved your issue with the custom dynamic category query. I’ll try to explain why your code was not working before and how you fixed it.
The custom dynamic category query is a function that allows you to filter the products in a specific category by a keyword in the product title. For example, if you have a category called “Hair Straighteners” and you want to show only the products that have the word “straightener” in the title, you can use this function to achieve that.
However, your original code had a problem: it was affecting all the queries on your site, not just the product category query. This means that whenever you clicked on a category, the function would try to filter the results by the keyword, but it would also affect the menu, the sidebar, the footer, and any other query on the page. This is why you saw some random page names instead of the store category.
To fix this problem, you added a condition to your code:
&& $query->is_main_query()
. This condition checks if the query is the main query of the page, which is the one that displays the products in the category. By adding this condition, you made sure that the function only affects the main query and not the others. This is why your code works fine now.I hope this helps you understand your code better. Please let us know if you have any questions or concerns. We are here to help you. ??.
Thanks @afzalpansuvi
Its work ?? One other question, I have noticed that the code look not only in product title, but in product description as well. Any suggestion how to modify below code that will only search in product tiles excluding description
function custom_dynamic_category_query($query) {
// Check if we are on the product category page and target a specific category
if (is_product_category(‘Prostownice do w?osów’) && $query->is_main_query()) {
// Specific word in the product title IMPORTANT: this part do not works exactly, beside the title the product description is taken. How to limit only to product title ??
$query->set(‘s’, ‘prostownica’);
}
}
add_action(‘pre_get_posts’, ‘custom_dynamic_category_query’);Hey,@piotrpepson!
As my colleague mentioned, providing custom code is beyond our scope of support.
If you need further help, you can reach out to the communities we shared above, ?WooCommerce Advanced Facebook group?or the?WooCommerce Community Slack. I’ll also leave this open for a bit in case someone from the community here are able to help you, okay?
Have a wonderful day!
- The topic ‘Smart category to to show the product that contains some word in the Title’ is closed to new replies.