Mở file functions.php trong child theme của bạn (nếu chưa có child theme, bạn nên tạo child theme để tránh mất thay đổi khi update theme). Thêm đoạn code sau:
//thông báo giờ đóng cửa
add_action('wp_footer', 'webdy_store_hours_flatsome');
function webdy_store_hours_flatsome() {
// Thiết lập múi giờ Việt Nam (UTC+7)
date_default_timezone_set('Asia/Ho_Chi_Minh');
// Lấy giờ hiện tại (24h format)
$current_hour = (int) date('H');
$current_minute = (int) date('i');
// Định nghĩa giờ mở và đóng cửa
$open_hour = 8; // 8 AM
$close_hour = 17; // 5 PM
// Kiểm tra nếu ngoài giờ hoạt động (8 AM - 5 PM)
$is_outside_hours = ($current_hour < $open_hour || $current_hour >= $close_hour);
// Nếu ngoài giờ, ẩn các nút và hiển thị thông báo
if ($is_outside_hours) {
?>
<style>
/* Ẩn nút Add to Cart trên trang sản phẩm */
.single_add_to_cart_button {
display: none !important;
}
/* Ẩn nút Add to Cart trong vòng lặp sản phẩm (shop, category) */
.product .add_to_cart_button {
display: none !important;
}
/* Ẩn nút Thanh toán ngay trên trang giỏ hàng */
.cart .checkout-button,
.wc-proceed-to-checkout .checkout-button {
display: none !important;
}
/* Ẩn nút Thanh toán ngay trong mini-cart (nếu có) */
.widget_shopping_cart .checkout {
display: none !important;
}
</style>
<script>
jQuery(document).ready(function($) {
// Thêm thông báo giờ đóng cửa với class "store-closed-notice"
var notice = '<div class="store-closed-notice" style="background: #f8d7da; color: #721c24; padding: 15px; text-align: center; margin-bottom: 20px;">Webdy hiện đang đóng cửa. Giờ mở cửa: 8:00 AM - 5:00 PM.</div>';
// Thêm thông báo vào trang sản phẩm
if ($('.single-product').length) {
$('.product-main').prepend(notice);
}
// Thêm thông báo vào trang shop/category
if ($('.shop-page').length) {
$('.shop-container').prepend(notice);
}
// Thêm thông báo vào trang giỏ hàng
if ($('.cart').length) {
$('.cart').prepend(notice);
}
});
</script>
<?php
}
}
Chào ! Bạn thấy nội dung này thế nào?





