I would like to show the woocommerce store notice demo_store only when store is closed. This is every tuesday. I thought about first getting the date, then remove the action and re-add it on tuesdays. I would love to learn how to do this.
function is_store_closed() {
// weekday[0] = "Sunday";
// weekday[1] = "Monday";
// weekday[2] = "Tuesday";
// weekday[3] = "Wednesday";
// weekday[4] = "Thursday";
// weekday[5] = "Friday";
// weekday[6] = "Saturday";
return (date('true', strtotime($date)) == 2);
}
function conditional_store_notice() {
// Remove default 'woocommerce_demo_store' notice
remove_action( 'wp_footer', 'woocommerce_demo_store' );
// Add back the woocommerce_demo_store' notice, but only if tuesday
if ( ! is_store_closed() ) {
add_action( 'wp_footer', 'woocommerce_demo_store' );
}
}
add_action( 'wp_footer', 'conditional_store_notice' );
You can remove that html from filter, Ideally it removes the content from rendering.
function is_store_closed() {
$timestamp = time();
return ( date( 'w', $timestamp ) === '2' );
}
add_filter( 'woocommerce_demo_store', function( $html, $notice ){
if( !is_store_closed() ){
return '';
}
return $html;
}, 10, 2 );
This code remove Store notice content on other days of week.