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:

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

报告相同问题?

悬赏问题

  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码