如何将资源链接到WooCommerce上的可预订产品计划?
我正在使用WooCommerce Bookings插件来处理我的业务预订。我希望能够以编程方式将资源添加到可预订的产品中。现在,我能够通过这样做来创建资源而没有任何问题:
$new_page_args = array(
'post_type' => 'bookable_resource',
'post_title' => $resource_name,
'post_status' => 'publish',
'post_author' => 1,
);
$resource_id = wp_insert_post($new_page_args);
但是我似乎找不到将新创建的资源与产品链接的方法。 我尝试执行此查询:
$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->prefix}wc_booking_relationships ( product_id, resource_id ) VALUES ( %d, %d )", $product_id, $resource_id ) );
它仍然不起作用。
I'm using the Woocommerce Bookings plugin to handle bookings for my business. I would like to be able to add resources to bookable products programmatically. Right now I'm able to create resources without any problems by doing this:
$new_page_args = array(
'post_type' => 'bookable_resource',
'post_title' => $resource_name,
'post_status' => 'publish',
'post_author' => 1,
);
$resource_id = wp_insert_post($new_page_args);
However I can't seem to find a way to link the newly created resource with a product.
I have tried executing this query:
$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->prefix}wc_booking_relationships ( product_id, resource_id ) VALUES ( %d, %d )", $product_id, $resource_id ) );
and it still doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我用来将旧预订链接到新资源的代码段。
它对我有用。
Here is a code snippet I used to link old bookings to new resources.
It worked for me.