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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
//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 } } |