Last active
January 19, 2016 14:32
-
-
Save claudiosanches/6879443 to your computer and use it in GitHub Desktop.
WooCommerce - Business hours.
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
<?php | |
/** | |
* Business hours. | |
*/ | |
function odin_wc_business_hours_redirect() { | |
if ( is_checkout() || is_cart() ) { | |
global $woocommerce; | |
// Set the timezone. | |
date_default_timezone_set('America/Sao_Paulo'); | |
// Get the current hour. | |
$hour = date( 'G' ); | |
if ( ! ( $hour >= 8 AND $hour <= 18 ) ) { | |
$woocommerce->add_error( __( 'Fora do Horário de Funcionamento', 'odin' ) ); | |
wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) ); | |
exit; | |
} | |
} | |
} | |
add_action( 'template_redirect', 'odin_wc_business_hours_redirect', 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment