I inserted the snippet with a plugin (WPCode) and the first test, as I mentioned, succesfully called the webhook but with no data.
I tried changing the format of the array and tried several things. But everytime the webhook did not receive the call anymore. Last one tried was with the following adjustment:
PHP Fatal error: Uncaught Error: Class "HivePressModelsBooking" not found in /usr/local/lsws/wordpress/wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(260) : eval()'d code:5
Booking duration is not correct. But upon looking at the code, I realise, if it’s possible to just get the end time, I don’t need the duration. Just the begin and end time of the booking.
And with booking date I meant the date of the appointment.
The reason I need this, is so I can schedule a videomeeting, integrating with AtomChat. AtomChat syncs with the wordpress users to know by userID which account should be joined for the converstation between client and consultant. And since Vendor is always connected to a Wordpress User, I’d need the Userid of the user behind the vendor instead of the vendor id.
Would that be possible?
The code that gets a linked order seems to be correct, please try checking this via error_log or var_dump. HivePress sets the booking ID in the hp_booking order meta.
Please try to use $order_id instead of $order. Here is detailed information on how to use var_dump PHP: var_dump - Manual
Please try to use the date function PHP: date - Manual to get the date in the standard format
For example date('Y-m-d', $booking->get_start_time());
If you mean getting the date when the booking was made then please try to use $booking->get_created_date()
I hope this guide will be helpful for you but please note that it can require advanced customization which can require hiring someone for custom work https://fwd.cx/hLhc73mQCD9R
Thank you @yevhen, that did the trick and it is working well in testing. I was wondering if the hook also is activated when the booking gets cancelled? Or does that require a special snippet?
I tested it and the webhook did not receive data when cancelling the booking. I didn’t find anything peculiar in the logs, so what could be the cause and solution?
Also, what variable can I use to send the status of the booking among the data that is send to the webhook? So when the webhook receives data, it can be determined whether it is a confirmed booking or a cancelled one.
Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress
If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY
Please try to use $booking->get_status() to get booking status
Thank you @yevhen. I’m a bit confused by your reply and I’ll try to explain why:
When I first considered HivePress, I contacted customer support and asked whether a feature was available to call a webhook. Customer support said yes and that I’d have to request a code snipped via the community.
I did just that and received from you guys a code snippet. Which, with some additional testing, works.
You mentioned somewhere in between, that if I needed advanced customization I would have to hire someone, which I understand, but all I needed was the code snippet to work.
I ask whether the code snippet would also work when a booking gets cancelled, you say yes, but upon testing it doesn’t work. And now suddenly this is deemed as a type of customization beyond your scope of support. If something doesn’t work than it’s a bug right? Not a request for advanced customization?
It feels as if I’m missing some context as to why this falls out of the support scope.
Sorry for the confusion, I guess @yevhen made the initial snippet too specific so it appeared like we provide customizations as part of the support scope, when referring to the forum I meant a sample snippet to show how to hook custom functions with a sample webhook request using wp_remote_post to the booking status change event.
Unfortunately, we can’t implement specific business logic for your website and debug custom code (this is something that we would estimate as custom work depending on the time spent), we can only provide general guidance regarding the development, and we’re happy to suggest common snippets (we have a collection of 100+ snippets and we add more based on the forum topics) although customization is completely beyond the support scope by default.
If you have a developer for custom work, or you’re familiar with PHP basics please try staring with this code snippet:
add_action(
'hivepress/v1/models/booking/update_status',
function( $booking_id, $new_status, $old_status, $booking ) {
// Check status.
if ( 'publish' !== $new_status ) {
return;
}
// Send request.
wp_remote_post(
'webhook-url-here.com',
[
'body' => [
// add webhook parameters here,
// e.g. booking details like $booking->get_something()
// or parameters requred by webhook (like the API key)
],
]
);
},
1000,
4
);
It sends a webhook request when a booking is confirmed.