在WooCommerce WordPress中,ui-datepicker-year只显示20年。
P粉720716934
P粉720716934 2023-08-06 21:20:13
[PHP讨论组]
<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() { ?&gt; &lt;script&gt; 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 }); }); &lt;/script&gt; &lt;?php } add_action('wp_footer', 'extend_date_of_birth_range');</pre> <p><br /></p>
P粉720716934
P粉720716934

全部回复(2)
P粉692052513

试一下这个

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

将"dateRange"变量放置如下:

// Replace "billing_date_of_birth" with the ID or name of your date of birth field
$('#billing_date_of_birth').datepicker('option', {
     yearRange: dateRange
});
P粉071602406

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

<?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');
?>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号