在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);

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.

Because you have two colections diferent and function each only iterates for one collection, could you make pull apart the collections

jQuery('#billing_state option').each(function() {
                var text = jQuery(this).text();
                jQuery(this).text(text.replace('Seleziona un\'opzione…',     'Seleziona una provincia')); 
jQuery('#shipping_state option').each(function() {
                var text = jQuery(this).text();
                jQuery(this).text(text.replace('Seleziona un\'opzione…',     'Seleziona una provincia')); 
            })