B
B
Boris Belov2016-11-03 22:06:49
WordPress
Boris Belov, 2016-11-03 22:06:49

How to make Woocommerce permalinks for category and products the same?

Hello.
The client wants the Product category base to have the Products category
and also the Product Permalinks to also start with Products.
1A553bOuKBKJLA.png
The problem is that when I do Product category base -> Products, and Product Permalinks -> Products, then a 404 error appears, and if I do, for example, Product Permalinks -> Product, then everything is ok.
But you need exactly Product category base -> Products and Product Permalinks -> Products, how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2016-11-03
@HeadOnFire

WordPress uses the base in the url to determine what the content type is and what request to make. Therefore, the same base for different types is not an option. The fact is that your beautiful url for it looks like this:

/products/sample-product/ - урл для человека
/products/([^/]+)(?:/([0-9]+))?/?$ - правило, по которому WP его парсит
index.php?product=sample-product&post_type=product&name=sample-product - вот во что он превращается для ядра

As you can see, post_type is requested in the resulting "machine" url, there is nothing related to product categories, so nothing will be searched for them, hence 404.
Also, it is important to understand that rewrite rules in WordPress come in an array, one after another, and he checks them in that order. The first one that came up will work, and further testing stops. Therefore, if you have 2 different rules for 1 base url, the one that comes first in the array of rules will work. The second turn simply will not reach.
In general, logically, the url structure should be:
/products/ - all products
/products/category/{category-name} - category of products
/product/{product-name} - one product
And sometimes you need to control the client's Wishlist.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question