Answer the question
In order to leave comments, you need to log in
How to display different shortcodes in different Woocommerce categories using Advanced Custom Fields?
I have a task in each of the created categories to display different shortcodes in a certain place.
Currently installed Advanced Custom Fields .
Configured like this:
As they say on the Internet, I tried it by pasting the code:
$term = get_queried_object();
$my_gallery = get_field('my_gallery', $term);
echo $my_gallery;
Answer the question
In order to leave comments, you need to log in
what you are doing in the screenshot is you are attaching a custom field to posts that have that category. To display it in the product archive in each card that has such a field, it is enough to use the simplest function the_field('slug'), well, you can also tighten the check. only this is a card template, tobish content-product.php
but as far as I understand, you need to display the field outside the cycle on the archive page, then your code is correct and the template is also correct, and you need to bind the field to Taxonomy equals Category. Fields will appear in product categories. Insert the actual sham shortcode into the text fields and display it like this
$term = get_queried_object();
$my_gallery = get_field('my_gallery', $term);
echo do_shortcode($my_gallery);
function archive_product_shortcode() {
$term = get_queried_object();
if ( function_exists('get_field') ) {
$my_shortcode = get_field('my_shortcode', $term);
echo do_shortcode( $my_shortcode );
}
}
add_action('woocommerce_archive_description', 'archive_product_shortcode', 20 );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question