以编程方式更新现有 Yith WooCommerce 预订的状态

问题描述 投票:0回答:1

我的一个客户正在 WordPress / WooCommerce 安装上使用 Yith WooCommerce 预订插件。

他想将其与他使用的外部程序连接,我陷入了从他的程序创建新预订的困境。

预订创建成功,后端看到一切正常,但产品页面前端Ajax日历不刷新,显示旧的可用情况。

我的代码的演示部分如下:

$booking = get_post(5404);    

$booking->post_status = 'bk-cancelled';
    
wp_update_post($booking);

$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $booking, array( 'ID' => 5404 ) );
clean_post_cache( 5404 );
do_action( 'yith_wcbk_booking_updated', $booking );
do_action( 'yith_wcbk_update_booking', 5404, $booking );

$booking = yith_get_booking( $booking );
$booking->save();

在此步骤中,我尝试以编程方式将现有 Yith WooCommerce 预订的状态更新为取消,尽管它在产品页面的后端工作,但不会清除日期。

有什么想法吗?

php wordpress woocommerce plugins woocommerce-bookings
1个回答
0
投票

使用可用的 Yith WooCommerce 预订方法尝试以下简化代码版本:

$booking_id = 5404;
$booking = yith_get_booking( $booking_id );
$booking->set_status('cancelled');
$booking->save();

它应该有效并解决您的问题。

找到文档:

© www.soinside.com 2019 - 2024. All rights reserved.