如何在wordpress中显示国家/地区电话代码?

Arm*_*n H 0 wordpress woocommerce

我无法编辑 woocommerce 结账页面。

我想添加我的国家/地区电话号码代码,例如 ( +88 ),但我无法做到这一点。

更新:

我尝试了此参考中的代码,并将以下代码添加到我的主主题(woodmart)function.php 中。

wp_enqueue_style( 'int-tel-phone-style', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/6.4.1/css/intlTelInput.css' );
wp_enqueue_script('int-tel-phone-js','https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/6.4.1/js/intlTelInput.min.js');
Run Code Online (Sandbox Code Playgroud)

最后在 footer.php 中添加了以下代码脚本

<script type="text/javascript">
  $("#billing_phone").intlTelInput();
</script>
Run Code Online (Sandbox Code Playgroud)

但它仍然不起作用。有什么帮助吗?

itz*_*kan 5

只需在活动主题的functions.php中添加以下代码片段即可完成这项工作 -

add_action( 'wp_footer', 'callback_wp_footer' );
function callback_wp_footer(){
    ?>
    <script type="text/javascript">
        ( function( $ ) {
            $( document.body ).on( 'updated_checkout', function(data) {
                var ajax_url = "<?php echo admin_url('admin-ajax.php'); ?>",
                country_code = $('#billing_country').val();

                var ajax_data = {
                    action: 'append_country_prefix_in_billing_phone',
                    country_code: $('#billing_country').val()
                };

                $.post( ajax_url, ajax_data, function( response ) { 
                    $('#billing_phone').val(response);
                });
            } );
        } )( jQuery );
    </script>
    <?php
}

add_action( 'wp_ajax_nopriv_append_country_prefix_in_billing_phone', 'country_prefix_in_billing_phone' );
add_action( 'wp_ajax_append_country_prefix_in_billing_phone', 'country_prefix_in_billing_phone' );
function country_prefix_in_billing_phone() {
    $calling_code = '';
    $country_code = isset( $_POST['country_code'] ) ? $_POST['country_code'] : '';
    if( $country_code ){
        $calling_code = WC()->countries->get_country_calling_code( $country_code );
        $calling_code = is_array( $calling_code ) ? $calling_code[0] : $calling_code;

    }
    echo $calling_code;
    die();
}
Run Code Online (Sandbox Code Playgroud)