• Resolved shenalorlof

    (@shenalorlof)


    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 back

    add_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 shenalorlof.
    • This topic was modified 3 years, 2 months ago by shenalorlof.
    • This topic was modified 3 years, 2 months ago by shenalorlof.
    • This topic was modified 3 years, 2 months ago by shenalorlof.
    • This topic was modified 3 years, 2 months ago by shenalorlof.
    • This topic was modified 3 years, 2 months ago by shenalorlof.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter shenalorlof

    (@shenalorlof)

    Ok fixed.. had to check the (if $cat) without going for the term

    • This reply was modified 3 years, 2 months ago by shenalorlof.
    Plugin Support abwaita a11n

    (@abwaita)

    Glad to hear that you were able to solve this one!

    Thanks for sharing your fix here.

    If you have any further questions, I recommend creating a new thread.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wrong category name on parent category archives’ is closed to new replies.