Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Last active January 19, 2016 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudiosanches/6879443 to your computer and use it in GitHub Desktop.
Save claudiosanches/6879443 to your computer and use it in GitHub Desktop.
WooCommerce - Business hours.
<?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