[Resolved] Assign a template to the products pages of a specific category
This thread is resolved. Here is a description of the problem and solution.
Problem:
Assign a template to the products pages of a specific category
Solution:
You can use the view/block filter hook "wpv_filter_force_template" to assign content template dynamically for single product posts based on the taxonomy term or product category.
Tell us what you are trying to do?
Hi, I'm trying to assign a product page template automatically based on the product category the product is assigned to. I have 1 main template I use for nearly all product except for 1 category. I've found a few threads online already. The problem is I don't have too much experience with api web hooks.
The above example is considering that you have term 511 available with taxonomy product_cat. Then it will assign the content template (ID) 12687 to that specific single product post.
Hi, I've added the code but the product template has not changed for the products pages. Could this be due to the other template being assigned to the Products (single)?
Can you please share what content template you want to assign to what category when single product post is displayed on the frontend.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I've deactivated the Toolset layouts plugin as you were not using it. Please note that Toolset Layouts plugin is in maintenance mode and we are not going to add any new features to it. if you are not using it, please delete that plugin. I just deactivated it.
I've added the static text "template called" to your content template at top:
=> hidden link
Then, I can see the code you added to "Custom Code" section:
Now, when I load the test page on frontend: hidden link
I can see that "template called" text at top, that means the code is working and 12687 template ID is assigned to test product post.