doudou6719 2018-04-06 13:56
浏览 47
已采纳

在Woocommerce结帐页面中替换“州”选择字段第一个选项文本

Why this code replace only my billing state default value text and not my shipping state default select value text?

 // Replace text in woo checkout
    function ea_custom_script_woo_checkout(){
    if(is_checkout()){
        echo "<script type=\"text/javascript\" >
            jQuery( document ).ready(function() {
                jQuery('#billing_state option, #shipping_state option').each(function() {
                    var text = jQuery(this).text();
                    jQuery(this).text(text.replace('Seleziona un\'opzione…', 'Seleziona una provincia')); 
                })
            });
        </script>";
    }
}
add_action('wp_footer', 'ea_custom_script_woo_checkout', 90, 1);
  • 写回答

2条回答 默认 最新

  • duanlangwen9597 2018-04-06 19:52
    关注

    May be because shipping fields are hidden at start… Please try the following:

    // Replace state select field placeholder option text in checkout 
    add_action('wp_footer', 'custom_script_in_checkout', 100, 1);
    function custom_script_in_checkout(){
    if( ! is_checkout() ) return;
        ?>
        <script type="text/javascript" >
            jQuery( function($){
                function changeStateOptionText(){
                    $('select[name=billing_state] option, select[name=shipping_state] option').each( function() {
                        if($(this).text() == "Seleziona un'opzione…")
                            $(this).text("Seleziona una provincia");
                    });
                }
                setTimeout( changeStateOptionText, 200);
    
                // To be sure (if shipping fields are hidden)
                $('checkbox[name=ship_to_different_address]').change(function() {
                    changeStateOptionText();
                });
            });
        </script>";
        <?php
    }
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?