How do I link a resource to a bookable product programmaticaly on woocommerce?

Viewed 20

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.

0 Answers
Related