Hello friends! Today I have come back and continue with the series of learning WordPress theme programming woocommerce. Today's article I will guide you to do the function of searching products by category in woocommerce.
This article applies not only to woocommerce but also to all cases of serch under a category, by tag, or under any taxonomy.
This function I have built in my seo standard sales code, you can refer.
Create html form search interface
The product search form by category will have 3 main parts:
- Section choose a category
- The search keyword entry section
- Button submit to start searching
We will have the interface according to the code below:
The select part will be to select the category, the input tag section is the area to enter keywords.
Assemble wordpress product search function by category
We will have the following code:
- Line 1 change action into the homepage, the method here is GET dentist.
- Line 2 Add a hidden input tag This input tag helps us Search only in products, don't search for good posts or pages
- From line 4 come line 26, we use the function wp_dropdown_categories To display select select category.
- Line 17 and line 22 Required values are: product_cat
- Line 24 Required value is slug
- Line 29 is the input tag to enter the keyword, Here has 1 mandatory value is name = "s"
- Line 31 required button tag type = "submit"
For themes that use woocommerce, we don't have search processing code because in the woocommerce plugin it already has the processing function ready. Our job is to pass the parameter as it will produce the correct result.
In case the search indicates a result, it will automatically redirect to the details page of that unique result.
Today I showed you how to do the product search function by catalog in woocommerce, I will try to write more articles in the near future.
The post Search products by category in WooCommerce appeared first on Blog Huy Kira.Read more :
- How to climb the Auto Chess rank with Feathered - Hunter - Knowledge sharing blog
- WinContig 2.4 Full - Software to defrag files, hard drives
- This altcoin could explode if it breaks out of strong resistance
- 49,342 Bitcoin is transferred back and forth between the whales, the community expects the price to rise
- Hướng dẫn sửa lỗi 403 Forbidden Error nhanh chóng 100% OK