wrong category name on parent category archives
-
Hi dear supporters,
I’m trying to show current category page name on the page above description, But the name shows wrong in parent categories
Attempt 1 – This is the code i was using
add_action( 'woocommerce_archive_description', 'woocommerce_category_name', 2 ); function woocommerce_category_name() { $terms = get_the_terms( get_the_ID(), 'product_cat' ); if ( $terms && ! is_wp_error( $terms ) ) : if ( ! empty( $terms ) && category_description($category_id) ) { echo '<div class="aviwoo_category_name">' . $terms[0]->name . '</div>'; } endif; }
————————————————————–
Attempt 2 – Tried to add this code but it rolls backadd_action( 'woocommerce_archive_description', 'woocommerce_category_name', 2 ); function woocommerce_category_name() { if ( is_product_category() ){ global $wp_query; $cat = $wp_query->get_queried_object(); $terms = get_term_meta( $cat->term_id, 'cat_name', true ); if ( $terms ) { echo '<div class="aviwoo_category_name">' . $cat->name . '</div>'; } } }
- This topic was modified 3 years, 2 months ago by .
- This topic was modified 3 years, 2 months ago by .
- This topic was modified 3 years, 2 months ago by .
- This topic was modified 3 years, 2 months ago by .
- This topic was modified 3 years, 2 months ago by .
- This topic was modified 3 years, 2 months ago by .
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘wrong category name on parent category archives’ is closed to new replies.