2

I've been trying to apply a gettext filter to return two different results for different product categories (or read as categories for posts, non-woocommerce specific).

I cant seem to get it right. This loads, but does not actually apply the conditional, it always defaults to else condition. What am I missing? This is added to my child theme's functions.php.

function my_text_strings( $translated_text, $text, $domain ) {
            switch ( $translated_text ) {
                        case 'Related Products' :
                                    if  (is_product_category( 'providers' ) ) {
                                        $translated_text = __( 'Check out these other Providers', 'woocommerce' );
                                        } else {
                                        $translated_text = __( 'Check out reviews of other Providers', 'woocommerce' );
                                        }
                                        break;
                                        }
            return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

1 Answer 1

1

I had success with the following where I specifically set the $domain. In your instance you might want to change $domain to $woocommerce. Take a look at the original related_products function and see how it is outputted using the localisation function to determine what domain to use.

Hope that helps

    function wpa_translate_email( $translated_text, $text, $domain ){
        if( $domain == 'woothemes' && $translated_text == 'E-mail' && is_front_page() )
            $translated_text = 'Enter your email for news, recipes and offers';

        return $translated_text;
    }

    add_filter( 'gettext', 'wpa_translate_email', 10, 3 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.