1

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; 
Ruvee
  • 8,611
  • 4
  • 18
  • 44
sot
  • 45
  • 6
  • 1
    Your question needs more details and clarity. 1- Where did you assign your `acf` field to? To the product? To a custom taxonomy? 2- You used `$taxonomy` variable first and then tried to assign a value to it, why? Were does the first one come from and why did you change it? Please clarify your question. – Ruvee Jan 29 '22 at 17:28
  • The acf field is assigned from an forms taxonomy group field. And am trying to add on custom taxonomy page. – sot Jan 29 '22 at 17:37

1 Answers1

4

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;
Ruvee
  • 8,611
  • 4
  • 18
  • 44