Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('mbhi_hours_entry', 'mbhi_change_hours_format',10,3);
- function mbhi_change_hours_format($entry, $location, $shortcode) {
- // Do nothing when closed that day.
- if($entry->hours === __('Closed','mabel-business-hours-indicator-pro'))
- return $entry;
- // Goal: go from "9 - 17:30" to "9h-17h30", so do two things: remove spaces around "-" and add "h" where needed
- // Remove spaces around by doing "trim".
- $arr = explode('-',$entry->hours);
- for($i = 0; $i< count($arr); $i++) {
- if(strpos($arr[$i],':') !== false)
- $arr[$i] = str_replace(':','h', trim($arr[$i]) );
- else
- $arr[$i] = trim($arr[$i]) . 'h';
- }
- $entry->hours = implode('-',$arr);
- return $entry;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement