Search

WCPT PRO offers a powerful search facility that is capable of using the keyword phrase entered by visitors and looking through product title, content, SKU, excerpt, category, attributes, custom fields and tags to yield comprehensive results. Moreover, using match weightage / relevance rules you can deliver more accurate search results.

Weightage rules 

You can find the weightage rules in WP Dashboard > Product Tables > Settings > Search > title rules, content rules, sku rules … etc  

  • Phrase exact: Applies when the match between the keyword phrase and the product field is exact. Eg: when title and keyword phrase are both “Chocolate sundae”.
  • Phrase like: Applies when the keyword phrase entered by user is contained within the field text. Eg: when keyword phrase is “Chocolate sundae” wherase the title is “Chocolate sundae ice-cream”.
  • Keyword exact: Applies when one of the keywords in the search phrase exactly matches a word within the field text. Eg: when keyword phrase is “Chocolate sundae” and the word “Chocolate” in this matches in the title “Chocolate ice-cream”.
  • Keyword like: Applies when one of the keywords in the search phrase is included within a word in the field text. Eg: when keyword phrase is “Choco treat” and the word “Choco” is a sub-word in the title “Chocolate ice-cream”.

In the case of attribute and custom field, you can set custom weightage for each term. This facility is very useful when, for example, you want to prioritize ‘genre’ matches over ‘artist’ matches for the keywords entered by user. In that case you would give the genere attribute higher match scores, therefore pushing up its results compared to artist attribute match results.

Using the checkbox next to any weightage rule you can outright disable the rule if you uncheck it.  

Search exact “keyword” only

Let us take an example where the search focuses on a custom field ‘manufacturing code’. In this case it may be necessary that the results for a keyword like ‘123’ only returns products with custom field ‘manufacturing code’ set to ‘123’ and not results for ‘1234’, ‘0123’ etc. 

To enable exact match, go to the global search settings > weightage rules > open the target where you want to search. In this example it is ‘custom fields’. Now disable all weightage rules for it except ‘Phrase exact’. Doing this instructs the plugin to only return products where the custom field value exactly matches the searched keyword.

 

You can do the same for any other search target areas as well where you only want exact matches – title, content, excerpt, SKU, custom field, attribute, category, tag. SKU example:

Resource usage / response speed

If you are searching through several product properties and have a large number of products on your site, your search results can end up taking a long time. To workaround this situation:

  • Ensure memcache is enabled on your server. This helps cache repeated database searches, therefore speeding results and reducing resource usage.
  • Only enable the fields that are most important. You may also want to consider combining different product properties into a single custom field dedicated for search, then target only that custom field for search.
  • Consider switching to a web host that offers the requisite resources to support your heavier search requirements.

Global search shortcode

A special search shortcode is included in WCPT PRO that lets you create a search bar with a category dropdown. You can place this shortcode on your site outside your product table, anywhere that accepts shortcodes, such as text widget, or add it to your product templates via PHP.

[wcpt_search clear_redirect="home" redirect="search"]

Using the category dropdown your site visitor can select the category they wish to search within, or they may search through all categories at once. The search facility will redirect them to the category page that they have selected.

clear_redirect=”home” lets you decide which page to show when user clears search. Possible values –

  • home : leads to homepage
  • shop : leads to woocommerce shop page
  • category : leads to current category page with the search cleared 

redirect=”shop” lets you decide on which page to show the search results. Possible values:

  • search : leads to the product search page. This is the default option.
  • category : takes visitor to the selected product category if they selected a product category in the search dropdown.

disable_category=”true” can be used to hide the category dropdown.

category_required=”true” can be used to make the category selection mandatory.

placeholder=”search” lets you set the placeholder text in the input box. For translations enter placeholder_*locale*=”Translation” where *locale* is the locale code like fr_FR for french, en_US for US region english, etc.

submit_label=”Submit” lets you set a text label for the submit button. For translations, use locale codes like: submit_label_fr_FR=”Submit”

all_label=”All” lets you change the label for ‘all categories’ option in the category dropdown. For translation, use locale codes like: all_label_fr_FR=”All”

exclude=”category-1, category-2″ will exclude categories from the dropdown.

include=”category-1, category-2″ will only show those categories in the dropdown. 

hide_search_icon=”true” will hide the search button icon.

width=”400px” sets a fixed width for the search box.

max_width=”800px” defines a limit for the possible width.

For styling the global search shortcode please see the Style Tips doc section “Global search shortcode”.

You can also add this shortcode directly via PHP to different parts of your site. You can copy paste the following examples in your child theme’s functions.php file:

Above archive page tables:

add_filter( 'wcpt_shortcode_attributes', 'wcpt_custom__search_bar_above_table' );
function wcpt_custom__search_bar_above_table($atts){
  if( ! empty( $atts['_archive'] ) && ! wp_doing_ajax() ){
    echo do_shortcode('[wcpt_search]');
  }
  return $atts;
}

Top of product archive pages:

add_action('woocommerce_before_main_content', 'wcpt_custom__search_bar_above_archive');
function wcpt_custom__search_bar_above_archive(){
  echo do_shortcode('[wcpt_search]');  
}

Live search / instant results / autocomplete

This feature is not part of WCPT PRO. However, you can use select 3rd party plugins that are compatible with WCPT PRO for live search. Please note:

  • When using 3rd party plugin for search results, the search settings of WCPT PRO, including weightage rules will not take effect.
  • The 3rd party plugin will affect the results only on the product search page of your site. You can replace the product grid on this page with product tables using the Archive override facility included in WCPT PRO.
  • The 3rd party search elements cannot be used ‘inside’ the WCPT container, navigation area. They will remain outside at another location on the page, either in the widget area, or top of page depending on the 3rd party plugin facilities.