Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. add_filter('mbhi_hours_entry', 'mbhi_change_hours_format',10,3);
  2. function mbhi_change_hours_format($entry, $location, $shortcode) {
  3.  
  4. // Do nothing when closed that day.
  5. if($entry->hours === __('Closed','mabel-business-hours-indicator-pro'))
  6. return $entry;
  7.  
  8. // Goal: go from "9 - 17:30" to "9h-17h30", so do two things: remove spaces around "-" and add "h" where needed
  9. // Remove spaces around by doing "trim".
  10.  
  11. $arr = explode('-',$entry->hours);
  12.  
  13. for($i = 0; $i< count($arr); $i++) {
  14. if(strpos($arr[$i],':') !== false)
  15. $arr[$i] = str_replace(':','h', trim($arr[$i]) );
  16. else
  17. $arr[$i] = trim($arr[$i]) . 'h';
  18. }
  19.  
  20. $entry->hours = implode('-',$arr);
  21.  
  22. return $entry;
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement