Skip to content

Instantly share code, notes, and snippets.

@MCKLtech
Last active August 7, 2023 14:29
Show Gist options
  • Save MCKLtech/78078fc4bb3e51b3d1712482d5842d0a to your computer and use it in GitHub Desktop.
Save MCKLtech/78078fc4bb3e51b3d1712482d5842d0a to your computer and use it in GitHub Desktop.
<?php
/* An example of two methods to retrieve only WooCommerce Bookings Products */
use WC_Product_Booking_Data_Store_CPT;
$booking_products_ids = WC_Product_Booking_Data_Store_CPT::get_bookable_product_ids();
foreach($booking_products_ids as $id) {
echo 'Product ID: '.$id;
$product = wc_get_product($id);
echo 'Product Name: '.$product->get_title();
}
/* Or you can also do this... */
use WC_Bookings_Admin;
$options = array();
foreach ( WC_Bookings_Admin::get_booking_products() as $bookable_product ) {
$options[ $bookable_product->get_id() ] = $bookable_product->get_name();
}
echo 'Products: '.print_r($options,true);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment