Friday, February 4, 2022

[FIXED] How to add ACF field after WooCommerce archive page title

Issue

I am trying to print an ACF field after the WooCommerce archive page title.

I use the following code but not working.

woocommerce_page_title();
global $post;
if( get_field('acf_field',$taxonomy . '_' . $termId) ):
    $taxonomy = get_query_var('taxonomy'); 
    $term_id = get_queried_object()->term_id; 
    the_field('acf_field', $taxonomy . '_' . $term_id);
else: 
endif; 

Solution

I'm not sure why you used global $post variable here, since you have not provided the entire code but I don't think you need it for outputting the acf field.

So try the following snippet:

woocommerce_page_title();

$term_id  = get_queried_object()->term_id;
$taxonomy = get_queried_object()->taxonomy;

$custom_field_value = get_field('you_acf_field_here', $taxonomy . '_' . $term_id);

if ($custom_field_value) :
    echo $custom_field_value;
else :
    echo 'NO CUSTOM FIELD FOUND!';
endif;


Answered By - Ruvee

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.