问题描述
在WooCommerce预订中,我有一个可预订的产品,我基本上希望成为其他三个可预订产品的父母。我想实现的是,当预订了主要的父产品时,它随后对3个子产品设置了可用性规则,以使其不可用。
为此,我查看了Adding availabilities programmatically to a bookable product on Woocommerce Bookings中的以下内容,然后进行了一些修改,然后进行了以下更改:
add_action('woocommerce_new_booking','modify_woocommerce_booking_date');
function modify_woocommerce_booking_date($booking_id)
{
$booking = get_wc_booking($booking_id);
$product_id = $booking->get_product_id();
//If the bundle is being booked
if ($product_id == 69096) {
//This is the array that will contain all the availabilities
$availabilities = array();
//Formatting the start and end date of the bookings to be Y-m-d format
$time = strtotime($booking->get_start_date());
$startdate = date('Y-m-d',$time);
$time = strtotime($booking->get_end_date());
$enddate = date('Y-m-d',$time);
//Create an array that contains the required fields (from_date and to_date are not necessary in some types of availabilities)
$availability = array(
'type' => 'custom',//I'm doing full day bookings rather than hours.
'bookable' => 'no','priority' => 10,'from_date' => wc_clean($startdate),'to_date' => wc_clean($enddate)
);
//If you need to add more than one availability,make a loop and push them all into an array
array_push($availabilities,$availability);
add_post_Meta(69047,'_wc_booking_availability',$availabilities); //Individual Product One
add_post_Meta(69093,$availabilities); //Individual Product Two
add_post_Meta(69094,$availabilities); //Individual Product Three
}
}
但是,这似乎不起作用。有什么我想念的吗?我需要在时间和日期中包括时间吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)