我正在尝试定制预订体验。我的产品是分布在一年中的旅游,滚动日历来查找可用的一天是效率不高的。我想要的是一个下拉列表,有下一个可用于该旅行的日子。对于我的情况,有没有什么插件或解决方案?
发布于 2015-07-17 17:41:13
该文件位于wp-content/plugins/woocommerce-bookings/templates/booking-form中
所描述的文章中的代码大部分都可以工作,但也有一些错误
警告: reset()要求参数1为数组,即在第54行的/home/betaacademyofflo/public_html/wp-content/plugins/woocommerce-bookings/templates/booking-form/date-picker.php中给定的字符串
警告:传递给each()的变量不是第55行/home/betaacademyofflo/public_html/wp-content/plugins/woocommerce-bookings/templates/booking-form/date-picker.php中的数组或对象
此错误在每个可用的日期都会出现。
我试图做的一个调整是,当前选择列表显示了我需要的每个日期的副本,以便只显示一次日期。
对于每个日期,我指的是开始日期,我的预订具有相同的开始日期和结束日期。
你可以在这里看到一个例子,example list我暂时抑制了错误。这是到目前为止的代码,几乎与code支持的OP版本相同。
<?php
$year = array();
$month = array();
$days = array();
$s;
$day1;
$i=0;
$j=0;
foreach ($availability_rules as $value) {
foreach ( $value as $value2) {
foreach ( $value2 as $value3) {
reset($value3);
while (list($key, $val) = each($value3)) {
$year[$i] = $key; //add year to array - $i is the count of how many course
reset($val);
while (list($key2, $val2) = each($val)) {
if($key2 < 10){
$month[$i] = '0'.$key2; //add the month value to another array - with leading 0
}else{
$month[$i] = $key2; //add the month value to another array
}
$s = "";
$j = 0;
reset($val2);
while (list($key3, $val3) = each($val2)) {
if($j==0||$j==1){
$s = $s . $key3 .',';
}else{
$s = $s . $key3;
}
if($j==0){
$day1[$i] = $key3; //add the day value to another array
}
$j++;
}
$days[$i] = $s;
}
$i++; //increments each time we loop through a year
}
}
}
}
$arrlength = 0;
$arrlength = count($year); //this is our total amount of courses
?>
<fieldset class="wc-bookings-date-picker <?php echo implode( ' ', $class ); ?>">
<legend><?php echo $label; ?>: </small></legend>
<select id="availableDates">
<option value="">Select Date</option>
<?php
if($arrlength==0){
echo "<option value=''>There are no dates</option>";
}else{
$todays_date = date("d-m-Y");
$today = strtotime($todays_date);
for($total_dates = $arrlength -1; $total_dates >= 0; $total_dates--){ //loop through total amount
$expiration_date =strtotime($day1[$total_dates].'-'.$month[$total_dates].'-'.$year[$total_dates]);
$actualdates = $day1[$total_dates]-$month[$total_dates]-$year[$total_dates];
$displaydates = $day1[$total_dates]/$month[$total_dates]/$year[$total_dates];
//$input = array( $day1[$total_dates]-$month[$total_dates]-$year[$total_dates]);
//$result = array_keys($input);
if ($expiration_date > $today) {
echo "<option value='$day1[$total_dates]-$month[$total_dates]-$year[$total_dates]'>$day1[$total_dates]/$month[$total_dates]/$year[$total_dates]</option>"; //pull in the index for each date array
}
}
}
?>我尝试过的东西;
对最终结果运行额外的foreach不起作用尝试array_unique不起作用
Anny guidance在这里将是最受欢迎的。
https://stackoverflow.com/questions/31047643
复制相似问题