Custom Woocommerce ACF Category Filters

We had a client recently that needed to be able to create product filters based on the product categories they were assigned to. This presented a problem because we didn’t want to clog up the taxonomy / category pages with a bunch of filter options and the user also needed to be able to edit these categories in the future.

We took the approach of adding some ACF fields to the product categories and then inserting a meta box on the products based on their selected categories which would list the ACF fields as checkboxes, similar to selecting a taxonomy.

It is hard to explain so here is a bunch of code and images to explain.

Here is our custom meta box displaying the filters that were created in the category page. Notice this is actually displaying the filters from ALL selected categories.
Here are the filters created in one category.
This is what the front end looks like. The checkboxes are FontAwesome icons.

Finally, here is the code needed to accomplish this.

All of this code goes into your “functions.php” file

Here is an example of what the front end HTML might look like.


Remove / Defer jQuery

If you use the WordPress built in jQuery you might have noticed taking some hits on your pagespeed. Here are a couple functions to increase your pagespeed score while still keeping jQuery usable.


Javascript Local and Cookie Storage

Just a couple functions to make working with Local Storage and Cookies a little easier.


Download and Update Post Content Images

Sometimes we have clients who have a lot of old blog posts. Often these blog posts have a lot of images in the content. Sometimes they are uploaded locally…sometimes they are not. I actually think serving images from 3rd parties is a great idea to offload the cost to your servers, but sometimes clients will request that we update their blogs so all the images are being served from their site.

Here is a quick script I wrote to do just that.

Good luck!

Highlight a search term and show its location in the excerpt

Sometimes a client will want the search term in the results page to show the first occurrence of the searched word in the content of that page. Here is some basic functionality to do that.


Add WordPress Stop Words

Sometimes a client will want to prevent certain words from being included in or affecting the search results. In order to remove these words from the search query we can just add them to the WP_Query stopwords like so: