Last active
February 11, 2021 10:29
-
-
Save nurul-umbhiya/d5724a68fee16964dfe770caf718e895 to your computer and use it in GitHub Desktop.
Dokan store open-close fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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