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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置