Skip to content
Advertisement

How can I remove parentheses from WooCommerce subcategory product count

On any default WooCommerce category page, it lists categories (product photo, title/link) with a number in parenthesis. For example, Finishing (6).

The page html looks like this:

<mark class="count">(6)</mark>

enter image description here

I tried this php to remove just the parenthesis, obviously that didn’t work:

function filter_woocommerce_subcategory_count_html( $mark_class_count_category_count_mark, $category ) {

    $mark_class_count_category_count_mark = ' <mark class="count">' . $category->count . '</mark>';

    return $mark_class_count_category_count_mark;
}

My goal is to style that count with a background color and border radius, which I can’t now because the parenthesis gets in the way.

Advertisement

Answer

From where do you call this function? this function does nothing in itself. In short, you are using it wrong.

Try this instead

function filter_woocommerce_subcategory_count_html ( $html, $category ) {
    $html =  '<mark class="count">' . esc_html( $category->count ) . '</mark>';
    return $html;
}
add_filter( 'woocommerce_subcategory_count_html', 'filter_woocommerce_subcategory_count_html', 10, 2 );
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement