S
S
sanhos2019-07-03 14:34:17
WordPress
sanhos, 2019-07-03 14:34:17

How to insert content in each product for a separate woocommerce category?

Good day, there are several categories, and for products of each category you need to display unique content (shorcode) (in the product). I'm not sure I explained the point exactly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Zhuk, 2019-07-03
@ivan_zhuck

If I understand correctly, it can be done like this:

$terms = wp_get_post_terms($post->ID, 'product_cat');
foreach ( $terms as $term ){
    if($term->slug === 'something'){
        do_shortcode('[shortcode_name]')
    }
};

The wp_get_post_terms function gets all the terms of the product_cat taxonomy associated with the product by its ID, then iterate through the received terms inside foreach and look for the right one, for example, by its slug, and when it is found, we execute what is required, for example, do_shortcode.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question