This members-only tutorial provides the steps to output WooCommerce products belonging to one or more product categories (or product tags) that have been checked when viewing pages of a Custom Post Type. The product category selection metabox is via Advanced Custom Field's Taxonomy field.
product_categories Taxonomy-type custom field for
When editing a Project CPT entry:
After implementing the tutorial viewing the above project singular page on the front end will show all the WooCommerce products that belong to the selected product category, Tshirts, in this case:
If more than 1 product category is selected by default, OR condition will be used i.e., all products that belong to any of the selected categories will appear. We can change this to use the AND operator i.e., products have to belong to all the selected categories.
When a parent product category is selected, products in its child categories will also appear.
If you have not already, register your Custom Post Type using a plugin like CPT UI.
Install and activate ACF if you have not already.
Create a new field group at Custom Fields > Add New.
Add a field named
product_categories of the
Ensure that Return Value is Term Object.
Attach the field group to your CPT.
Create and edit the Oxygen Template that applies to singular pages of your CPT.
Add a Section perhaps below the WordPress > Dynamic Data > Title and Content in which you would like to show the "related" products.
Add a Code Block.
This is a premium members-only content.
To view the rest of the content, please sign up for membership ($47/month or $599 one-time).
Already a member? Log in below or here.