programing

Woocommerce 3에서 관련 제품 제목 이름 변경

minimums 2023. 3. 4. 14:26
반응형

Woocommerce 3에서 관련 제품 제목 이름 변경

Woocommerce에서 Related Products 텍스트로 변경하기 위해 다음과 같은 기능을 가지고 있었습니다.

function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Related Products' :
            $translated_text = __( 'Related Books', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

항상 완벽하게 동작했지만 Woocommerce 버전 3.0 이후로는 이 기능은 더 이상 작동하지 않습니다.

버전 3.0 이상에서 동작시키려면 어떻게 수정해야 합니까?

이거 먹어봐, 나랑 잘 돼

add_filter(  'gettext',  'wps_translate_words_array'  );
add_filter(  'ngettext',  'wps_translate_words_array'  );
function wps_translate_words_array( $translated ) {
     $words = array(
                // 'word to translate' = > 'translation'
               'Related Products' => 'Check out these related products',  
     );
     $translated = str_ireplace(  array_keys($words),  $words,  $translated );
     return $translated;
}

이제 그것에 대한 필터가 있다.이름은 "woocommerce_product_related_products_heading"입니다.

그래서 당신은 당신의 테마 함수에 작은 조각들을 추가할 수 있습니다.다음과 같은 php 파일:

add_filter('woocommerce_product_related_products_heading',function(){

   return 'My Custom nice related title';

});

간단한 대체 방법

템플릿 파일의 테마를 통해 Woocommerce 템플릿을 덮어씁니다. 여기서 직접 이름을 변경할 수 있습니다.

<h2><?php esc_html_e( 'Related products', 'woocommerce' ); ?></h2>

수신인:

<h2><?php esc_html_e( 'Related Books', 'woocommerce' ); ?></h2>

언급URL : https://stackoverflow.com/questions/45688753/rename-related-products-title-in-woocommerce-3

반응형