Taxonomies Dropdown (categories)

Custom WordPress taxonomies can be used easily with the Availability Search for WooCommerce Bookings to filter the search results by taxonomy terms. The feature requires you to know the slug (name) of your custom taxonomies. The Availability Search will then automatically pull in and display every term under the taxonomies in a dropdown selector.

Using built-in Product Categories?

Instead of using custom taxonomies, you can use the below features with the standard WooCommerce product categories. Product categories are already a taxonomy, which means we can use them.

The taxonomy slug for product categories is product_cat. You can use product_cat in the below examples.

[availability_search taxonomies="product_cat"]
Code language: JSON / JSON with Comments (json)

Using custom taxonomies?

This document assumes that you’ve already set up and applied taxonomies to your bookable products.
Custom taxonomies allow you to create categories for your WordPress posts, products & bookable products.

We recommend using the Custom Post Type UI plugin to get started.
You can learn more about what WordPress taxonomies are in this post.

Adding a taxonomy as a search filter

So you’ve got your custom taxonomies ready to go. All you need to do is add the following taxonomy attribute to the shortcode. For example my custom taxonomy is called Experience Type and the slug is experience_type. Add the slug like so:

[availability_search taxonomies="experience_type"]Code language: JSON / JSON with Comments (json)

You can also add multiple taxonomies by comma separating the slugs.

[availability_search taxonomies="experience_type, age_group"]Code language: JSON / JSON with Comments (json)

Availability Search will now display the name of your taxonomy as a label (if display labels are turned on in the settings) and all the taxonomy terms are available in the dropdown. Your customers can now filter available products by the taxonomy terms.

Expierence type taxonomy & terms used with other filters.

Limiting Taxonomy Terms

You can limit the options in the taxonomy dropdown by including or excluding specific terms. In this example, I have a custom taxonomy with the slug of experience_type. You’ll need to replace it with your own. So the pattern for the shortcode:

include_terms_ + Taxonomy Slug.

exclude_terms_ + Taxonomy Slug.

Include only specific terms

Every term will be included by default. You can selective choose only a few to be included in the drop down. If you want to include most of your terms then excluding will be the easier option.

Normal Product Categories Example:

[availability_search taxonomies="product_cat" include_terms_product_cat="31, 5"]Code language: PHP (php)

Custom Taxonomies Example:

[availability_search taxonomies="experience_type, another_tax" include_terms_experience_type="21, 10"]Code language: PHP (php)

Then we want the dropdown to only show 2 of our terms, we’ll need the ID’s of those terms. In our case the final attribute will look like so include_terms_experience_type="21, 10"

NOTE: If you want to display the hierarchical view for parent & child terms, then you must include each parent & child ID.

Exclude only specific terms

Use the exclude option when there are only a few terms that you wish to remove from the drop-down. All other terms will be included automatically.

You can use this method for multiple taxonomies and also exclude terms like this: exclude_terms_experience_type="21, 10"

Finding the term ID

The easiest way to find the ID of a specific term go to the edit page for the term. In the below example you’ll see the ID located in the URL.

The below example is for the default product categories.

Overriding The Taxonomy Label.

The name of the taxonomy in your WordPress install will automatically be used for the drop-down label. You can however override the label for the taxonomy by adding an attribute to the shortcode. We’ll add taxonomy_label_experience_type="New Label" to the shortcode. Remember to replace “experience_type” with your taxonomy slug.

[availability_search taxonomies="experience_type, another_tax" taxonomy_label_experience_type="New Label" include_terms_experience_type="21, 10"]Code language: PHP (php)

That’s all, happy searching!

Was this page helpful?