Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Change AM/PM to am/pm in the WooCommerce Booking and Appointment Plugin for WooCommerce?

We have already seen in one of our previous posts to change the hour format for the booking type duration-based time. Now, let’s also see how to change the timeslot format for fixed-time booking types when using the Booking and Appointment Plugin for WooCommerce. This customization is flexible in scenarios where customers more commonly prefer lowercase “am” and “pm” in their timings.
This is more suitable depending on the target audience or the nature of the service being booked. This timeslot format can make the interface feel more approachable and user-friendly.

Solution: Change AM/PM to am/pm in the WooCommerce Booking and Appointment Plugin for WooCommerce

The code helps in presenting the time slots in a clear and standardized manner, such as ‘10.00am – 12.00pm’ rather than ”10.00 AM – 12.00 PM”.

Note: The customization works only if the Timezone Conversion option present in the plugin settings is disabled.

How to Change AM/PM to am/pm in the WooCommerce Booking and Appointment Plugin for WooCommerce? - Tyche Softwares
/** 
 * Changing time slots format on the front end dropdown.
 *
 * @param array $timeslots Array of Time Slots.
 * @todo - This option is not working with the Timezone option enabled.
 */
function bkap_time_slot_filter_after_chronological( $timeslots ) {

	foreach ( $timeslots as $key => $value ) {

		$explode_time = explode( ' - ', $value );
		$time         = date( 'g.ia', strtotime( $explode_time[0] ) );

		if ( isset( $explode_time[1] ) ) {
			$to_time = date( 'g.ia', strtotime( $explode_time[1] ) );
			$time    = $time . ' - ' . $to_time;
		}

		$timeslots[ $key ] = $time;
	}
	return $timeslots;
}
add_filter( 'bkap_time_slot_filter_after_chronological', 'bkap_time_slot_filter_after_chronological', 10, 1 );

Output

When customers visit the booking page, they will now see the time slots displayed in a format like ‘9.00am – 11.00am’, which has been updated from the previous format of ‘9.00 AM – 11.00 PM’.

How to Change AM/PM to am/pm in the WooCommerce Booking and Appointment Plugin for WooCommerce? - Tyche Softwares

Let’s also look into the previous time format that was displayed as AM/PM before implementing the code snippet.

How to Change AM/PM to am/pm in the WooCommerce Booking and Appointment Plugin for WooCommerce? - Tyche Softwares

We have covered a wide range of customizations, from simply changing the time slots format to more complex tasks like customizing pricing based on selected durations. If you would like to enhance your site with any specific customizations, please leave a comment below.

Browse more in: Code Snippets, WooCommerce Booking & Appointment, WooCommerce How Tos

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x