Support

Account

Home Forums General Issues Custom WYSIWYG Field in WooCommerce Product Category

Solved

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.

  • $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

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Custom WYSIWYG Field in WooCommerce Product Category’ is closed to new replies.