0
votes

I don't get it!!! I have managed to include the product category description in their respective pages. I have 6 categories which with four of them I need to add a description. From the four, three worked as it should. However, there is one of them that not only shows its description but also another category's.

Categories

There are two of each category for multiligual purpose. But you can see the four categories I need to add the description.

1 - Tops 2 - Bottoms 3 - One Pieces 4 - Sport Wear

The first three worked as it should. Ie. Bottoms category page.

enter image description here

But the fourth, Sport Wear keeps showing not only its description but also the Top category's as well.

enter image description here

I have already recreated the category Sport Wear, but it remained the same way. I have no clue why this is happening. Any idea would be very much appreciated.

Here is the link: https://morenabeachwear.com/en/product-category/sport-wear/

And here the code I used to loop and display description.

function action_woocommerce_archive_description( ) { 

global $post;
$args = array( 'taxonomy' => 'product_cat');
$terms = wp_get_post_terms($post->ID,'product_cat', $args);

foreach ($terms as $term) {

    if (is_product_category()) {

        echo $term->description;

    }
   }
 }; 
  add_action( 'walker_edge_after_page_title','action_woocommerce_archive_description', 10, 2 );
1
Not sure this has anything to do with it, but do you need to have the $args in wp_get_post_terms()?git-e-up
@git-e-up How would you get the description otherwise?stemon
$terms should still work without the 3rd parameter in there. You've already established that the taxonomy is product_cat in your second param. developer.wordpress.org/reference/functions/wp_get_post_termsgit-e-up
Yep, if no $args the default is all. So it does work as well.stemon

1 Answers

1
votes

It turned out I didn't need the loop. And made sure to echo the first item of the array returned from wp_get_post_terms

function action_woocommerce_archive_description( ) { 

global $post;
$terms = wp_get_post_terms($post->ID,'product_cat');

    if (is_product_category()) {
        echo $terms[0]->description;
    }
}; 

add_action( 'walker_edge_after_page_title', 'action_woocommerce_archive_description', 10, 2 );