Populate hidden fields with product category and sub-category

Hi All,

I need to automatically populate one hidden field with the product’s category and a second hidden field with the product’s sub-category. Is this possible and if so how?

Thank you!!

Hi Logan,

You won’t be able to use the embed_post merge tag to perform this action as you’ll need to programmatically pull the categories out of the post and assign them using the ‘hook’ method of Dynamically Populating a Field:

The above article includes an example for populating the ‘post author’ and that’s the methodology you should adopt for grabbing the categories of the post.

You can use either wp_get_post_categories:

or get_the_categories:

Hope that helps!

Hi Jim,

Thank you for your reply. I will look into this.

Kind regards

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.