搜索

首页  >  问答  >  正文

在WooCommerce WordPress中,ui-datepicker-year只显示20年。

<p>我需要更新function.php文件,使其显示99年而不仅仅是20年。我正在使用Bizberg主题。<br /><br />我尝试了这个方法,但没有成功扩展时间范围,问题在于滚动条仍然只允许20年,我需要99年。</p><p><br /></p> <pre class="brush:php;toolbar:false;">function extend_date_of_birth_range() { ?> <script> jQuery(function($) { var currentYear = new Date().getFullYear(); var startYear = currentYear - 99; var endYear = currentYear - 10; // Replace "billing_date_of_birth" with the ID or name of your date of birth field $('#billing_date_of_birth').datepicker('option', { yearRange: startYear + ':' + endYear }); }); </script> <?php } add_action('wp_footer', 'extend_date_of_birth_range');</pre> <p><br /></p>
P粉720716934P粉720716934599 天前671

全部回复(2)我来回复

  • P粉692052513

    P粉6920525132023-08-07 19:41:24

    试一下这个

    1

    var dateRange = '"'+startYear+' : '+endYear+'"';

    将"dateRange"变量放置如下:

    1

    2

    3

    4

    // Replace "billing_date_of_birth" with the ID or name of your date of birth field

    $('#billing_date_of_birth').datepicker('option', {

         yearRange: dateRange

    });

    回复
    0
  • P粉071602406

    P粉0716024062023-08-07 16:12:42

    将此函数添加到function.php文件中,希望这能帮到你。

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    <?php

    function extend_date_of_birth_range() {

        ?>

        <script>

            jQuery(function($) {

                var currentYear = new Date().getFullYear();

                var startYear = currentYear - 99;

                var endYear = currentYear - 10;

                var dateRange = '"'+startYear+' : '+endYear+'"';

     

                // Replace "billing_date_of_birth" with the ID or name of your date of birth field

                $('#billing_date_of_birth').datepicker('option', {

                    yearRange: dateRange

                });

            });

        </script>

        <?php

    }

    add_action('wp_footer', 'extend_date_of_birth_range');

    ?>

    回复
    0
  • 取消回复