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 project CPT:

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.

Step 1

If you have not already, register your Custom Post Type using a plugin like CPT UI.

Step 2

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 product_cat Taxonomy.

Ensure that Return Value is Term Object.

Attach the field group to your CPT.

Step 3

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 $399 one-time).

Already a member? Log in below or here.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE

Comments

You need to be logged in to view and post comments.
Not a member yet? Join here.
magnifiercross
>
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: