ajax - 用于选择日期的 WooCommerce 预订 AJAX 代码
问题描述
我当前的项目需要根据所选日期的计算自定义显示一些额外的信息。我写了一个函数,我找不到预订系统返回数据和计算基于有效日期的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>';}
解决方案
日期选择时长ajax在wp-content/plugins/woocommerce-bookings/dist/frontend.js,搜索成功,这个文件最后一个是验证选择时长后的代码。
推荐阅读
- reactjs - 更新许多使用 Mongoose 的条件
- c++ - Windows 包含文件夹中缺少 vcruntime.h?
- spring-batch - 使用for循环批量遍历子目录
- angular - 使用 ngForOF 指令创建 TemplateRef 类型的 QueryList
- python - 将 Python 字节字符串转换为 UTF-8/ASCII
- python - 在 Python 中由 scipy.fftpack.in 创建的数组中查找特定值的位置
- javascript - 当父级有一个带有jQuery的元素时如何删除特定元素?
- python - 如何使用 Python 中的正则表达式在字符串中查找重复的子字符串?
- google-bigquery - 无法将数据加载到摄取时间分区表中
- c++ - 如何为 C++ Visual Studio 2019 指定应用程序图标?