dongzhun8449 2018-09-26 00:56
浏览 109
已采纳

如何在Woocommerce结帐页面中更改“有优惠券?”文字

I'm trying to translate "Have a coupon?" text in Woocommerce checkout page using this code:

function custom_strings_translation( $translated_text, $text, $domain ) {
  switch ( $translated_text ) {
    case 'HAVE A COUPON?' : 
        $translated_text =  __( 'TIENES UN CUPÓN?', '__x__' );
        break;
}

  return $translated_text;
}
add_filter('gettext', 'custom_strings_translation', 20, 3);

But It doesn't work.

Please can someone tell me why?

  • 写回答

1条回答 默认 最新

  • downloadbooks_2014 2018-09-26 02:03
    关注

    It doesn't work because the text is not in capitals and you are not using the right variable.

    There is 2 ways to change this text (the second way seems the best):

    1) Using gettext filter hook this way:

    add_filter('gettext', 'custom_strings_translation', 20, 3);
    function custom_strings_translation( $translated_text, $text, $domain ) {
        if( $text == 'Have a coupon?' ){
            $translated_text =  __( 'Tienes un cupón?', $domain );
        }
        return $translated_text;
    }
    

    Code goes in function.php file of the active child theme (or active theme). Tested and works.


    2) Using woocommerce_checkout_coupon_message filter hook that will allow you more changes:

    add_filter( 'woocommerce_checkout_coupon_message', 'custom_checkout_coupon_message', 20, 1 );
    function custom_checkout_coupon_message( $notice ) {
        return __( 'Tienes un cupón?', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Haga clic aquí para ingresar su código', 'woocommerce' ) . '</a>'
    }
    

    Code goes in function.php file of the active child theme (or active theme). Tested and works.


    Related:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known
  • ¥15 用msg发消息出现的问题
  • ¥15 unity3d机械臂
  • ¥20 工控机出现散热器转一下停一下这种情况,是什么原因造成的