以编程方式将可用性添加到 Woocommerce Bookings 上的可预订产品
Adding availabilities programmatically to a bookable product on Woocommerce Bookings
我在网站上有一个表单,允许用户创建可预订的产品。但是,我找不到如何使用 Woocommerce php 函数创建可用性间隔。有人有想法吗?
这是我创建产品的方式
$post_id = wp_insert_post( array(
'post_title' => $_POST["title"],
'post_content' => $_POST["description"],
'post_status' => 'publish',
'post_type' => "product",
) );
wp_set_object_terms( $post_id, 'booking', 'product_type' );
在同一项目的另一部分,我使用 get_post_meta 函数来获取可用性。我知道可用性是来自 post 的元数据,但我不确定如何更改这些。我尝试使用通常的 add_post_meta( $post_id, '_wc_booking_availability', $availability );
但这没有用。关于 Woocommerce 可用性,我是否遗漏了什么?
附带说明一下,是否有更详细的 Woocommerce 预订文档?
他们网站上的 developer documentation 仅涵盖以编程方式创建产品的基础知识。
如果其他人需要的话,我找到了答案。
//This is the array that will contain all the availabilities
$availabilities = array();
//Create an array that contains the required fields (from_date and to_date are not necessary in some types of availabilities)
$availability = array(
'type' => 'time:range', //Replace time:range with the type you need
'bookable' => 'yes',
'priority' => 10,
'from' => wc_booking_sanitize_time( "01:00" ),
'to' => wc_booking_sanitize_time( "03:00" ),
'from_date' => wc_clean( "2018-10-02" ),
'to_date' => wc_clean( "2018-10-02" )
);
//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( $post_id, '_wc_booking_availability', $availabilities );
我在这里找到它,但我根据需要修改了它
https://wordpress.stackexchange.com/questions/233904/how-to-add-date-range-in-woocommerce-with-code
我在网站上有一个表单,允许用户创建可预订的产品。但是,我找不到如何使用 Woocommerce php 函数创建可用性间隔。有人有想法吗?
这是我创建产品的方式
$post_id = wp_insert_post( array(
'post_title' => $_POST["title"],
'post_content' => $_POST["description"],
'post_status' => 'publish',
'post_type' => "product",
) );
wp_set_object_terms( $post_id, 'booking', 'product_type' );
在同一项目的另一部分,我使用 get_post_meta 函数来获取可用性。我知道可用性是来自 post 的元数据,但我不确定如何更改这些。我尝试使用通常的 add_post_meta( $post_id, '_wc_booking_availability', $availability );
但这没有用。关于 Woocommerce 可用性,我是否遗漏了什么?
附带说明一下,是否有更详细的 Woocommerce 预订文档?
他们网站上的 developer documentation 仅涵盖以编程方式创建产品的基础知识。
如果其他人需要的话,我找到了答案。
//This is the array that will contain all the availabilities
$availabilities = array();
//Create an array that contains the required fields (from_date and to_date are not necessary in some types of availabilities)
$availability = array(
'type' => 'time:range', //Replace time:range with the type you need
'bookable' => 'yes',
'priority' => 10,
'from' => wc_booking_sanitize_time( "01:00" ),
'to' => wc_booking_sanitize_time( "03:00" ),
'from_date' => wc_clean( "2018-10-02" ),
'to_date' => wc_clean( "2018-10-02" )
);
//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( $post_id, '_wc_booking_availability', $availabilities );
我在这里找到它,但我根据需要修改了它 https://wordpress.stackexchange.com/questions/233904/how-to-add-date-range-in-woocommerce-with-code