Home › Forums › Backend Issues (wp-admin) › Show ACF field and title only on specific product category › Reply To: Show ACF field and title only on specific product category
@bulldogsnare As I can understand, you have created a date field for the product category taxonomy and you want to display it in your product category archives. Here is one approach to do that –
function tax_date_field(){
// get the current taxonomy term
$term = get_queried_object();
//ACF field
$date = get_field('class_dates', $term);
$class_date = '';
if( is_tax('product_cat') && $date ) {
$class_date = sprintf(
'<div class="class-date"><label>%s</label>%s</div>',
esc_html__('Post Dates:', 'your-themes-text-domain'),
esc_html( $date )
);
}
return $class_date;
}
Now you can echo the function to your product category archives. To do that, WooCommerce have some hooks for the taxonomy archive page which you can find inside archive-product.php
template file inside WooCommerce plugin folder.
Here I am hooking it to woocommerce_before_shop_loop
. In your functions.php –
add_action('woocommerce_before_shop_loop', 'show_post_dates', 11);
function show_post_dates(){
echo tax_date_field();
}
Now the field will be shown at product taxonomy archives. Let me know if you have any questions.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.