How to get data from bookings

Hi there,
what are the code snippets for user information like this one?

$booking->get_user__id()

I want to get the
client email address
listing name
vendor email address from a new booking.

Also, I’d like to be able to extract the order id of Woocommerce

Hi,

If the booking object is already available, you can get the information in this way:

$user=$booking->get_user();
$listing=$booking->get_listing();
$vendor=$booking->get_listing__vendor();

In this way, you will get objects and in them, you can get fields e.g., in this way: $email=$user->get_email();. You can get the Product ID in a separate PHP snippet. Please note that the product’s listing ID is set in the post_parent field.

​I hope this is helpful to you.

Great, thanks I’ll work with this!

Hi again,
I tried this, but I don’t get the names of listings and users/experts?
Is there something missing or wrong on the list above? The booking object is already there.

> $data = [
> 				'booking_date_created' => $booking->get_created_date(),
> 				'booking_duration' => round(($booking->get_end_time() - $booking->get_start_time()) / (60 * 60 * 24)),
> 				'booking_client' => $booking->get_user__id(),
> 				'booking_consultant' => $vendorname,
> 				'booking_order' => $order_id,
> 				'booking_start_time' => date('Y-m-d H:i', $booking->get_start_time()),
> 				'booking_end_time' => date('Y-m-d H:i', $booking->get_end_time()),
> 				'username' => $user,
> 				'useremail' =>$user->get_email(),
> 				'listingname' =>$booking->get_listing()

Hi,

Please note that listings, users, and vendors are objects, so this will return an object, not a value: $booking->get_listing(). That is, if you equate it to a listing, then you need to add the following: $listing->get_title() or $booking->get_listing__title() .

I believe this will be useful to you.

Great, thanks a lot Andrii. I guess the same applies to the names of vendor and client?
get_title() or something else? Where can I find all the description of the different values?

The listing name works now, thanks a lot!
I still don’t get a name of the vendor nor user, and only user email works. Is the way to get the email for the vendor different?

Hi,

If you have a vendor object, then you first need to get the user through $vendor->get_user(), and after that, get_email of the user object or get_user__email immediately. As for the list of fields, you can view them using var_dump($vendor->_get_fields()), for example.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.