yabdali
Forum Replies Created
-
I have created an issue in Github for the same. Please share information and screenshots there.
Thank you for your support…
I am using docker image wordpress:php8.2-fpm so its PHP 8.2
Thanks, I used the following code, I think it extends WBK_ModelUtils with some additional functions/methods…
$service_category = new WBK_Service_Category($category_id);
Hi, thanks for your inputs… I used the code below, I am able to get the webba shortcode parameters as shown here: the found is the actual shortcode, shortcode attributes are the attributes extracted.
Can you please advise me on how to get the list of services for a category?
Found webbabooking shortcode: [webbabooking category=4]
Shortcode attributes: {"category":"4"}
Found webbabooking shortcode: [webbabooking service=9]
Shortcode attributes: {"service":"9"}function extract_webbabooking_shortcode_attributes() {
if (is_single() || is_page()) {
global $post;
$pattern = get_shortcode_regex();
$content = $post->post_content;
$shortcode_found = false;
if (preg_match_all('/' . $pattern . '/s', $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
if ($match[2] == 'webbabooking') {
$shortcode_found = true;
$shortcode = $match[0]; // The full shortcode
$atts = shortcode_parse_atts($match[3]);
$json_atts = json_encode($atts);
// Log the original shortcode content and parameters
error_log('Found webbabooking shortcode: ' . $shortcode);
error_log('Shortcode attributes: ' . $json_atts);
// Print the JSON content at the footer
add_action('wp_footer', function() use ($json_atts) {
echo '<script type="application/json" id="webbabooking-shortcode-attributes">' . $json_atts . '</script>';
});
}
}
}
if (!$shortcode_found) {
add_action('wp_footer', function() {
echo '<script type="application/json" id="webbabooking-shortcode-attributes">{}<\/script>';
});
}
}
}
add_action('wp', 'extract_webbabooking_shortcode_attributes');Thanks, What would the value or the pattern for the $shortcode = ‘
my_shortcode
‘; be? Is it something like[webbabooking service=52]
? Can you please elaborate more?Thanks again, what are the options to get the service ID or services IDs? I The first and most important part is reading those, my code was using a manual static and hard-coded approach which doesn’t fulfill production deployment requirements. I need a way to read the IDs whenever a page which has a form is loaded!
Hi, further information to clear any doubts..
I add the booking form to the tour pages using the blocks editor as shown in the screen in the link, https://imgur.com/zPsVwOf and not using the[webbabooking service=52]
in case this what you were asking about above. In case this is not what you meant, I will assume you are referring to how I obtain the information based on the booking form. In this case, yes I want to get the attributes but in my case I don’t use shortcode when adding the form and wasn’t able to find a way to get the attributes of the Booking form Block which could be due to my lack of knowledge. Lets say I have a form with one or more services, I want to be able to get the attributes of those services.The output of the (final) JSON-LD can be anywhere within the body tag of the page, below the booking form should be fine.
I tried your suggested approach about using add_shortcode function. I used code snippet plugin and created a test code with a static variable for the service ID, did data transformation compliant with JSON-LD schema. Then used the shortcode name (
debug_log_shortcode
) in a test page and I can see the output as shown in the link below. Not sure if this is the optimal approach, let me know if I can get the same result in a better way. I haven’t figured yet how to get the service name and the description yet, if you can point out on how to do this. Please ignore the naming convention, it is a quick mock up.
https://imgur.com/YUvzzZP// Define custom shortcode function custom_debug_log_shortcode() { // Assuming WBK_Service class is already available // Set service ID (replace with your actual service ID) // Needs improvement: fetching service ID or IDs, and doing iteration for generating JSON-LD for each service $service_id = 8; // Create an instance of WBK_Service class $service = new WBK_Service($service_id); // Get business hours data $business_hours = $service->get_business_hours(); // Reformat business hours data (assuming it's JSON) if (json_decode($business_hours) !== null) { $reformatted_data = reformat_business_hours($business_hours); } else { return "<!-- Business hours data is not in JSON format. -->"; } // Get availability range $availability_range = $service->get_availability_range(); // Get duration $duration = $service->get_duration(); // Get price $price = $service->get_price(); // Generate JSON-LD schema $json_ld_schema = generate_json_ld_schema($availability_range, $duration, $price, $reformatted_data); // Return the JSON-LD schema inside a script tag return '<script type="application/ld+json">' . $json_ld_schema . '</script>'; } // Function to reformat business hours data function reformat_business_hours($business_hours_json) { // Weekday names dictionary $weekdays = [ "1" => "Sunday", "2" => "Monday", "3" => "Tuesday", "4" => "Wednesday", "5" => "Thursday", "6" => "Friday", "7" => "Saturday" ]; // Function to convert seconds to time string (HH:MM) function convertsecondsToTime($seconds) { $hours = intval($seconds / 3600); $minutes = intval(($seconds % 3600) / 60); return sprintf("%02d:%02d", $hours, $minutes); } // Decode JSON data $business_hours_data = json_decode($business_hours_json); // Reformat data structure $new_data = ["business_hours" => []]; foreach ($business_hours_data->dow_availability as $item) { $dayOfWeek = $weekdays[$item->day_of_week]; $startTime = convertsecondsToTime($item->start); $endTime = convertsecondsToTime($item->end); // Include timezone (replace with your desired timezone) $timezone = "Asia/Muscat"; // Or any valid timezone $new_data["business_hours"][] = [ "day_of_week" => $dayOfWeek, "day_of_week_number" => $item->day_of_week, "start" => $startTime, "end" => $endTime, "timezone" => $timezone ]; } // Encode to JSON string with indentation $json_string = json_encode($new_data, JSON_PRETTY_PRINT); return $json_string; } // Function to generate JSON-LD schema function generate_json_ld_schema($availability_range, $duration, $price, $reformatted_data) { // Sample event name and description $event_name = "Daily Boat Tour"; $event_description = "A daily boat tour that runs between 08:00 and 12:00 for " . intval($duration / 60) . " hours and " . ($duration % 60) . " minutes each, offering a scenic experience at Bandar Rowdha marina."; // Decode reformatted business hours data $business_hours_data = json_decode($reformatted_data, true); // Calculate schedules and group identical schedules $schedule_groups = []; foreach ($business_hours_data['business_hours'] as $day) { $start_time_seconds = strtotime($day['start']); $end_time_seconds = strtotime($day['end']); $service_duration_seconds = $duration * 60; for ($i = 0; $i + $service_duration_seconds <= $end_time_seconds - $start_time_seconds; $i += $service_duration_seconds) { $schedule_start = date("H:i", $start_time_seconds + $i); $schedule_end = date("H:i", $start_time_seconds + $i + $service_duration_seconds); $schedule_key = $schedule_start . '-' . $schedule_end . '-' . $day['timezone']; if (!isset($schedule_groups[$schedule_key])) { $schedule_groups[$schedule_key] = [ "@type" => "Schedule", "startDate" => $availability_range[0], "endDate" => $availability_range[1], "repeatFrequency" => "P1D", "startTime" => $schedule_start, "endTime" => $schedule_end, "duration" => "PT" . intval($duration / 60) . "H" . ($duration % 60) . "M", "scheduleTimezone" => $day['timezone'] ]; } } } // Convert schedule groups to array $schedules = array_values($schedule_groups); // JSON-LD schema structure $json_ld = [ "@context" => "https://schema.org", "@type" => "Event", "name" => $event_name, "description" => $event_description, "startDate" => $availability_range[0], "endDate" => $availability_range[1], "location" => [ "@type" => "Place", "name" => "Bandar Rowdha Marina", "address" => [ "@type" => "PostalAddress", "streetAddress" => "Bandar Rowdha marina", "addressLocality" => "Muscat", "addressRegion" => "Muscat", "addressCountry" => "Oman" ] ], "offers" => [ "@type" => "Offer", "price" => $price, "priceCurrency" => "OMR", "availability" => "https://schema.org/InStock", "validFrom" => $availability_range[0] . "T08:00:00+04:00", "validThrough" => $availability_range[1] . "T12:00:00+04:00" ], "eventSchedule" => $schedules ]; // Encode JSON-LD schema to string return json_encode($json_ld, JSON_PRETTY_PRINT); } // Register shortcode add_shortcode('debug_log_shortcode', 'custom_debug_log_shortcode');
Hi,
Yes, but it could be a Webba booking block or a shortcode. The website admin will add either webba blocks or shortcode on any page. There could be one service, or multiple services based on a category filter.
I want to check and extract the service ID or IDs if there are more than one service. When I read the IDs, I want to output the JSON LD code into the WP Footer. Section.
Thanks alot for your response. Just to clarify few things. I tried the above using code snippet by just setting a static value of one of the services and I can see the output into the html code of the page. Also, the intention is that code will run on each page that has a service form, it needs to detect the service ID or the service IDs of the services on the form, then pull the data (dates and time slots/or repetition frequency) and accordingly construct the JSON-LD.
So far, when trying to get the service IDs on a page with a form which has more than one service, the code isn’t able to get except one service. I am outputting the results into debug.log so I can have better understanding of what is going on with the code. Can you shed light how would I be able to detect the service IDs if more than service is on the form? The the output comes from code that checks for which blocks get loaded, not sure if there is a webba hooks or functions that can be used to check for the service IDs of the services populated by the form.
The rationale behind this is that we a search engine hits the page, the services data will be available in a syntax that can be parsed for events or tours. This will definitely make your plugin more attractive for people since most of the booking plugins lack such feature.
[03-Jun-2024 20:37:02 UTC] Checking block: webba-booking/form
[03-Jun-2024 20:37:02 UTC] Webba Booking Form block found. Full block content: Array
(
[blockName] => webba-booking/form
[attrs] => Array
(
[serviceId] => 1
[categoryId] => 3
)
[innerBlocks] => Array
(
)
[innerHTML] =>
<div>[webbabooking category=3]</div>
[innerContent] => Array
(
[0] =>
<div>[webbabooking category=3]</div>
)
)
[03-Jun-2024 20:37:02 UTC] Webba Booking Form block attributes: Array
(
[serviceId] => 1
[categoryId] => 3
)
[03-Jun-2024 20:37:02 UTC] Detected services: Array
(
[0] => 1
)
[03-Jun-2024 20:37:02 UTC] Only one Webba Booking service found.Just an additional note, I was able to identify wp-json api as listed below but there list of methods and required fields/parameters especially for the post methods are not clearly defined.
/wp-json/wbk/v2/
/wp-json/wbk/v1/
Forum: Plugins
In reply to: [Schema & Structured Data for WP & AMP] How to disable global schemaIs there any guide about how to co-exist with Rank Math? I have similar challenge, I use woocommerce and it looks that things are messed up after installing Rank Math. Also, I when I try to customize the schema by adding a new property, I don’t get any Rank Math related options. Like Rank Math Title or description. I don’t want to enter data into two different areas as this increases the maintenance work.. Appreciate your guidance. Thanks.
- This reply was modified 5 months, 4 weeks ago by yabdali.
Forum: Plugins
In reply to: [Schema & Structured Data for WP & AMP] Missing field “itemReviewed”I have the same issue. I have product schema with reviews enabled for specific pages. I run Rank Math as well in case it matters. I have another product schema with reviews for post type product which seems to be working fine except for minor optional issues. Can you please help?
Forum: Themes and Templates
In reply to: [Neve] Footer Widgets: How to change the layout for mobileThanks, I ended up using the following CSS as the picture widget4 was squeezed and wanted it to appear in a separate line.
@media (max-width:700px){ .hfg-grid.nv-footer-content.hfg-grid-top.row--wrapper.row { display: flex; flex-wrap: wrap; }
Forum: Themes and Templates
In reply to: [Neve] Footer Widgets: How to change the layout for mobileThanks, the url is https://www.capitano.om/