• Hello,
    I am trying to translate the function subcategory_count_markup (class-astra-woocommerce.php) with my custom plugin.

    How to edit this function in my custom plugin? I tried this:

    add_filter( 'subcategory_count_markup', 'subcategory_count_markup_custom' );
    function subcategory_count_markup_custom( $content, $category ) {
    
        if ($category->count > 4) {
            $content = sprintf(
                _nx( '<mark class="count">%1$s Produktów</mark>', '<mark class="count">%1$s Rodzaji</mark>', $category->count, 'product categories', 'astra' ),
                number_format_i18n( $category->count ));
        } else if ($category->count < 5) {
            $content = sprintf(
                _nx( '<mark class="count">%1$s Produkty</mark>', '<mark class="count">%1$s Rodzaje</mark>', $category->count, 'product categories', 'astra' ),
                number_format_i18n( $category->count ));
        }
    
        return $content;
    }

    But it doesn’t work…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @goodoskyy

    It seems you are using the wrong filter, we do not have any filter by ‘ subcategory_count_markup’

    Please try and use ‘ woocommerce_subcategory_count_html’ instead of ‘ subcategory_count_markup ‘

    The new code will look like this –

    add_filter( 'woocommerce_subcategory_count_html' , 'subcategory_count_markup_custom' );
    
    function subcategory_count_markup_custom( $content, $category ) {
    
    if ($category->count > 4) {
    $content = sprintf(
    _nx( '<mark class="count">%1$s Produktów</mark>', '<mark class="count">%1$s Rodzaji</mark>', $category->count, 'product categories', 'astra' ),
    number_format_i18n( $category->count ));
    } else if ($category->count < 5) {
    $content = sprintf(
    _nx( '<mark class="count">%1$s Produkty</mark>', '<mark class="count">%1$s Rodzaje</mark>', $category->count, 'product categories', 'astra' ),
    number_format_i18n( $category->count ));
    }
    
    return $content;
    }

    I hope that helps.

    Regards,
    Suman

    Thread Starter goodoskyy

    (@goodoskyy)

    Hi,
    Thank you, but unfortunately it doesn’t work.

    Critical error. Only 1 category is loading and in the place where first “x products” should be there is information about a critical error and all site is broken.

    Regards

    Hello @goodoskyy

    Can you try to remove the existing filter and try the code again?

    remove_filter( ‘woocommerce_subcategory_count_html’, ‘subcategory_count_markup’ , 10 );

    Also if the error still exists can you verify the code again.

    I hope that helps.

    Regards,
    Suman

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to translate product counts (‘subcategory_count_markup’ function)?’ is closed to new replies.