Home › Forums › General Issues › Custom WYSIWYG Field in WooCommerce Product Category
I’m using ACF and WooCommerce and would like to display a custom WYSIWYG field for my product categories. While I have seen this covered before, I’m still a little confused regarding just how to do this.
Here’s the code I’ve been trying out (with no luck so far):
<?php
$term = get_field('about_this_product_category', 'product-cat');
echo $term
?>
My goal here is to display the results of this field for the current product category. I have seen where you can specify a specific product category in your code, but I’d rather have it automatically display results if possible.
Any ideas of what I’m doing wrong?
Eventually figured this out! FYI, here’s the code in case it helps anyone. The name of my WYSIWYG field is ‘about_this_product_category’, which you would replace with your own field name.
<?php
// vars
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
// load desc for this taxonomy term (term object)
$thumbnail = get_field('about_this_product_category', $queried_object);
// load desc for this taxonomy term (term string)
$thumbnail = get_field('about_this_product_category', $taxonomy . '_' . $term_id);
?>
<?php the_field( 'about_this_product_category', $queried_object ); ?>
I copied the archive-product.php from the WooCommerce plugin directory into a new /woocommerce/ folder inside my theme.
Thanks for this, really helped me out as i have been struggling with this for a while now.
Hi, I keep getting:
Notice: Undefined property: stdClass::$taxonomy
and
Notice: Undefined property: stdClass::$term_id
on the base shop page, which is an archive, however a page also.
Anyone else experiencing this? Or can explain why it’s happening?
Thanks
Thanks so much for this, have been searching for a solution for a couple hours! SO glad you posted this.
Hit the same bug on default shop page as described. Then discovered this related post under support and was able to configure working solution…
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
if( get_field('about_this_product_category', $taxonomy . '_' . $term_id) ) {
the_field( 'about_this_product_category', $queried_object );
};
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
// load desc for this taxonomy term (term object)
$thumbnail = get_field('category_description', $queried_object);
// load desc for this taxonomy term (term string)
$thumbnail = get_field('category_description', $taxonomy . '_' . $term_id);
echo '<p class="dop_widget_p">' . get_field( 'category_description', $queried_object ) . '</p>';
Wrap the text in a tag and add style
The topic ‘Custom WYSIWYG Field in WooCommerce Product Category’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.