php 根据日期查询,php – 按可用日期查询woocommerce预订

我在我的woocommerce网站上使用

Woothemes booking

当我构建自定义搜索产品时,我还要搜索可用性,这里是我应该如何管理B.O的可用性以及插件如何存储到数据库

a:8:{i:0;a:4:{s:4:"type";s:4:"days";s:8:"bookable";s:3:"yes";s:4:"from";s:1:"3";s:2:"to";s:1:"3";}i:1;a:4:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:4:"from";s:10:"2015-07-09";s:2:"to";s:10:"2015-07-09";}i:2;a:4:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:4:"from";s:10:"2015-07-08";s:2:"to";s:10:"2015-07-08";}i:3;a:4:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:4:"from";s:10:"2015-07-10";s:2:"to";s:10:"2015-07-10";}i:4;a:4:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:4:"from";s:10:"2015-07-15";s:2:"to";s:10:"2015-07-15";}i:5;a:4:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:4:"from";s:10:"2015-07-16";s:2:"to";s:10:"2015-07-16";}i:6;a:4:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:4:"from";s:10:"2015-07-17";s:2:"to";s:10:"2015-07-17";}i:7;a:4:{s:4:"type";s:6:"months";s:8:"bookable";s:2:"no";s:4:"from";s:1:"8";s:2:"to";s:1:"8";}}

我可以从wordpress内置函数get_post_meta中检索这些值,

$avail = get_post_meta($product->id, '_wc_booking_availability');

结果是:

Array

(

[0] => Array

(

[type] => days

[bookable] => yes

[from] => 3

[to] => 3

)

[1] => Array

(

[type] => custom

[bookable] => yes

[from] => 2015-07-09

[to] => 2015-07-09

)

[2] => Array

(

[type] => custom

[bookable] => yes

[from] => 2015-07-08

[to] => 2015-07-08

)

[3] => Array

(

[type] => custom

[bookable] => yes

[from] => 2015-07-10

[to] => 2015-07-10

)

[4] => Array

(

[type] => custom

[bookable] => yes

[from] => 2015-07-15

[to] => 2015-07-15

)

[5] => Array

(

[type] => custom

[bookable] => yes

[from] => 2015-07-16

[to] => 2015-07-16

)

[6] => Array

(

[type] => custom

[bookable] => yes

[from] => 2015-07-17

[to] => 2015-07-17

)

[7] => Array

(

[type] => months

[bookable] => no

[from] => 8

[to] => 8

)

)

正如您所看到的,用户可以在一天或一个月的范围内指定产品是否可预订,所以我的问题是如何进行sql查询以检查此产品是否有可用的日期变量,我认为meta_query会做工作(如下所示),但我如何指定不可用的日期?你怎么想?

if($_GET['when']){

/* checkIsAValidDate() >> check date format */

if ( checkIsAValidDate( $_GET['when'] ) ){

$quand = $_GET['when'];

$available = array(

"post_type" => "product",

"meta_query" => array(

"relation" => "AND",

"key" => '_wc_booking_availability',

"value" => $when,

'compare' => 'IN'

)

);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值