Skip to content

Instantly share code, notes, and snippets.

@nurul-umbhiya
Last active February 11, 2021 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurul-umbhiya/d5724a68fee16964dfe770caf718e895 to your computer and use it in GitHub Desktop.
Save nurul-umbhiya/d5724a68fee16964dfe770caf718e895 to your computer and use it in GitHub Desktop.
Dokan store open-close fix
function dokan_is_store_open( $user_id ) {
$store_user = dokan()->vendor->get( $user_id );
$store_info = $store_user->get_shop_info();
$open_days = isset( $store_info['dokan_store_time'] ) ? $store_info['dokan_store_time'] : '';
$current_time = dokan_current_datetime();
$today = strtolower( $current_time->format( 'l' ) );
if ( ! isset( $open_days[ $today ] ) ) {
return false;
}
$schedule = $open_days[ $today ];
$status = isset( $schedule['open'] ) ? $schedule['open'] : $schedule['status'];
if ( 'open' === $status ) {
if ( empty( $schedule['opening_time'] ) || empty( $schedule['closing_time'] ) ) {
return true;
}
$open = $current_time->modify( $schedule['opening_time'] );
$close = $current_time->modify( $schedule['closing_time'] );
if ( $open <= $current_time && $close >= $current_time ) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment