首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于选择日期的WooCommerce Bookings AJAX代码

用于选择日期的WooCommerce Bookings AJAX代码
EN

Stack Overflow用户
提问于 2021-04-14 23:27:56
回答 1查看 63关注 0票数 0

我目前的项目需要定制地显示一些额外的信息的基础上,已选定的日期计算。我已经编写了一个函数,但是我找不到预订系统根据有效日期返回数据和计算以触发函数的AJAX代码。我的函数很简单:

代码语言:javascript
复制
function calculate_date_duration() {
    var year_1 = document.querySelector('.selection-start-date').getAttribute('data-year');
    var month_1 = document.querySelector('.selection-start-date').getAttribute('data-month');
    var date_1 = document.querySelector('.selection-start-date a').textContent;
    var year_2 = document.querySelector('.selection-end-date').getAttribute('data-year');
    var month_2 = document.querySelector('.selection-end-date').getAttribute('data-month');
    var date_2 = document.querySelector('.selection-end-date a').textContent;
    var day_1 = new Date(year_1, month_1, date_1);
    var day_2 = new Date(year_2, month_2, date_2);
    console.log(day_1);
    console.log(day_2); 
    var day_selected = day_2.getTime() - day_1.getTime(); 
    var date_duration = parseInt(day_selected / (1000 * 60 * 60 * 24)) +1;
    console.log(date_duration);
    var display_pane = document.querySelector('.wc-bookings-booking-cost');
    display_pane.innerHTML = display_pane.innerHTML + '<br>Total booking cost:<strong><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + (date_duration*120) + '</bdi></span></strong>';}
EN

回答 1

Stack Overflow用户

发布于 2021-04-15 12:36:32

日期选择持续时间ajax在wp-content/plugins/woocommerce-bookings/dist/frontend.js,搜索成功,此文件中的最后一个是验证所选持续时间后的代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67094629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档