PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

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

 February 04, 2022     php, taxonomy-terms, woocommerce, woocommerce-theming, wordpress     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing