Skip to content
Advertisement

Woocommerce: How to show Product Attribute name and Category name on title

Using the answer provided in this thread (Woocommerce: How to show Product Attribute name on title when in a category page and “filtering” products via ‘?pa_attribute=’ on address bar) I would like to display the category as well as the attribute name. I have a separate JS function that is currently updating the page_title when a filter is applied but that is only loading after ajax has finished. So in this event it would not load till after the filter is applied.

In the event that a user uses the nav to get to the category, currently only the attribute is displaying in the page_title. Looking to also display the category. I believe this would work out of the box if I organized my products in to subcategories but due to how the filtering is being set up I elected not to go this route. I can explain in further detail why I had to take this approach if anyone is interested.

I have left the commented out code in so that you can see the approach I was attempting to take. If this is confusing can edit it out.

JavaScript

Also, I have included the JS I am using to apply page_title in the event a filter selection occurs. Ideally it would be great if I could handle it all via a JS file as I am much more familiar with JS and just starting to dive in to php. I am using the WOOF – WooCommerce Products Filter and modifying some of the code to accomplish what I need.

JavaScript

Advertisement

Answer

So was able to get this to work by taking my JS and adding it in as a script within my functions.php. So essentially I was able to eliminate the custom_woocommerce_page_title filter.

Function.php

JavaScript

Then the woof woocommerce filter js that updates the title when a new select occurs after the AJAX.

JavaScript

will probably pare it down by just calling the script function from within the woof js after ajax.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement