Home › Forums › Backend Issues (wp-admin) › Show ACF field and title only on specific product category
I need to show custom dates using a field titled ‘Class Dates’. I have created the ACF field but how do I add that field including the title of that field only to specific categories on woocommerce using a shortcode? And if that isn’t possible what other way is there? Any information or snippets to help would be greatly appreciated.
Many thanks
Matt
@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.
Hi @amitbiswas06.
Thank you for your reply. But I don’t think you’ve fully understood what I was after, apologies if I have cause any confusion.
I have created an ACF field called class_dates which is only visible on the product category called ‘courses’.
However, I want to give this information a title so that customers can easily see what this date is. i.e.:
Class Dates & Time (h2 title)
31/12/2020 at 9pm (class date field).
Ive used the ACF shortcode to add this field to the Woocommerce product page template but I can’t pass through the title to the product page just the field text.
You must be logged in to reply to this topic.
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 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.