I’ve got the same problem described in this post:
[WordPress URL rewrite for WooCommerce attributes, except that I need to filter by attribute not only inside a category.
Unfortunately, I cannot post a comment before reaching a higher reputation, so I’m creating a new question.
I defined a manufacturer attribute and if I want to browse all products from a certain manufacturer, I can use a url like www.example.com/shop/?filter_manufacturer=230, where 230 is the attribute ID.
I tried adding a endpoint, like suggested in the post linked above above, but I cannot get the rewrites working; for example, if I try to open www.example.com/shop/manufacturer/manufacturer_name I get a 404 error.
It’s not clear to me if I should change anything in the permalink settings in WordPress and, if yes, how.
I’ve always flushed the rewrite rules after every edit, BTW.
2
Answers
The missing link between your question regarding WooCommerce attributes and the linked answer is that product attributes are merely taxonomies with a ‘pa_’ appended to their name.
In your case the taxonomy is called “pa_manufacturer”. WooCommerce sets these up by default to have no query var attached.
So in lieu of filtering
query_vars
we are going to target when WooCommerce registers that particular taxonomy. I’ve also modified to remove anonymous functions.In my example I am using “color”, so adjust to “manufacturer”. I was able to then go to a URL of
http://example.com/shop/color/black
and see all the black products. Note that this doesn’t get you a term archive where/shop/color
will list all the colors. That is a different question and a lot more work.I didn’t test the activation part, so if you get 404s after activating you can just delete the whole activation function and simply go to Settings>Permalinks and save the permalinks again.
EDIT
Adding some screenshots of my settings in case it will help determine why you are getting 404s:
Here are my permalinks settings:
and here is the WooCommerce setting for determining the product archive page:
And finally, here is the result of visting:
http://local.wordpress.dev/shop/color/black/
Where
shop
is the pretty permalink for the product archive page set above. All items have a ‘black’ color attribute.I had a similar problem and was able to solve it like this:
Sample Url: c/phone-cases/iphone-8-plus/
Resulting Rewrite: index.php?product_cat=phone-cases&filter_model=iphone-8-plus