用于选择日期的 WooCommerce 预订 AJAX 代码

时间:2021-04-14 15:27:56

标签: ajax woocommerce

我当前的项目需要根据所选日期的计算来自定义显示一些额外信息。我写了一个函数,我找不到预订系统返回数据和计算基于有效日期的AJAX代码来触发我的函数。 我的功能很简单:

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>';}

1 个答案:

答案 0 :(得分:0)

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