# Smart Business Hours

**Contributors:** KDT4U Solutions  
**Tags:** business-hours, contact-button, whatsapp, zalo, messenger  
**Requires at least:** 5.8  
**Tested up to:** 6.9
**Requires PHP:** 7.4  
**Stable tag:** 1.0.0  
**License:** GPLv2 or later  
**License URI:** https://www.gnu.org/licenses/gpl-2.0.html

Intelligent Call Now button that automatically adapts based on your business hours, cache-resistant, with support for holidays.

## Description

Smart Business Hours is the most intelligent contact button for WordPress. 
It automatically changes its appearance and behavior based on whether your business is currently open or closed, ensuring your visitors always get the right message at the right time.

### 🎯 Key Features

- **Smart Time Detection** - Automatically detects if your business is open (works with cache plugins!)
- **Visual Hour Matrix** - Easy-to-use grid interface for setting business hours (hours in rows, days in columns)
- **Multiple Contact Options** - Phone, WhatsApp, Zalo, Facebook Messenger, Telegram, Email
- **Ultra-Lightweight** - Less than 50KB total size, won't slow down your site
- **Cache Compatible** - Works perfectly with WP Rocket, W3 Total Cache, and all major caching plugins
- **Customizable Appearance**
  - 3 button styles (Modern, Classic, Minimal)
  - 3 button sizes (Small, Medium, Large)
  - Custom colors
  - 5 position options
- **Display Triggers**
  - Show immediately
  - After scroll percentage
  - After time delay
- **Responsive Design** - Perfect on all devices

### 🚀 Why This Plugin?

**Problem:** Traditional contact buttons don't adapt to business hours. Visitors click "Call Now" at 2 AM and get voicemail. This creates a poor user experience and wastes potential leads.

**Solution:** Smart Business Hours automatically shows the right call-to-action based on your actual availability:
- **During Business Hours:** "Call Now" (green, with phone icon)
- **Outside Business Hours:** "Leave Message" (red, with message icon)  
- **Holidays/Emergency:** Custom message

**Cache-Resistant Technology:** Unlike other plugins, this works perfectly with caching. The time check happens in JavaScript on the client-side, so even if your page is cached, visitors always see the correct status.

### 📊 Perfect For

- Local businesses (restaurants, salons, shops)
- Professional services (lawyers, doctors, consultants)
- E-commerce with phone support
- Service businesses with specific hours
- International businesses with timezone support

### 🌟 What Makes It Special

1. **Matrix Interface** - Most intuitive hour selection system (hours in rows, days in columns)
2. **Template System** - Quick setup with pre-made schedules (9-5, 24/7, weekends only)
3. **Copy Function** - Set Monday's hours, copy to all weekdays with one click
4. **Zero Configuration** - Works out of the box with sensible defaults
5. **Performance Optimized** - Uses vanilla JavaScript, no jQuery dependency on frontend

## Installation

### Automatic Installation

1. Go to WordPress Admin → Plugins → Add New
2. Search for "Smart Business Hours"
3. Click "Install Now"
4. Activate the plugin
5. Go to "Business Hours" in the admin menu
6. Configure your business hours and contact information

### Manual Installation

1. Download the plugin ZIP file
2. Go to WordPress Admin → Plugins → Add New → Upload Plugin
3. Choose the ZIP file and click "Install Now"
4. Activate the plugin
5. Configure settings at "Business Hours" menu

### First-Time Setup (5 minutes)

1. **Enter Contact Information**
   - Phone number (with country code)
   - WhatsApp, Zalo, Messenger links (optional)
   - Email address (optional)

2. **Set Business Hours**
   - Click on the matrix grid to select working hours
   - Or use a template
   - Drag to select multiple cells at once

3. **Customize Appearance**
   - Choose button position (bottom-right, bottom-left, etc.)
   - Select button style (modern, classic, minimal)
   - Pick your brand colors

4. **Save and Done!** 
   The button will automatically appear on your website

## Frequently Asked Questions

### How does it work with cache plugins?

The plugin uses client-side JavaScript to check the current time, so even if your page is cached, visitors always see the correct status. The time calculation happens in their browser, not on your server.

### Can I have different phone numbers for morning and afternoon?

Yes! This is a Pro feature called "Shift Management". You can assign different contact numbers for different time periods.

### Does it support lunch breaks (split shifts)?

Yes! You can add multiple time slots per day. For example:
- 8:00 AM - 12:00 PM
- 1:00 PM - 5:00 PM

### Can I hide the button completely when closed?

Yes! Go to Display Settings → Off-Hours Behavior → "Hide button completely"

### Does it work with page builders?

Yes! It works with all page builders (Elementor, Divi, Beaver Builder, etc.) because it adds the button via WordPress hook, not shortcode.

### Can I add holidays?

Yes! includes a holiday manager where you can:
- Add custom holidays
- Set recurring holidays (e.g., Christmas)

### Is there a shortcode?

Yes! Use `[sbh_cta]` to place the button anywhere. 

Shortcode parameters:
```
[sbh_cta position="bottom-right" style="modern" size="medium"]
```

### How do I test if it's working correctly?

1. Open your website in an incognito window
2. Check the button appearance during and outside business hours
3. Use browser DevTools to change system time for testing

### Can I use it on multiple sites?

Free version: Yes, on unlimited sites  
Pro version: 1 license = 1 site

### What happens if I deactivate the plugin?

All your settings are saved in the database. If you reactivate later, everything will be restored. To completely remove all data, use the "Delete Plugin" option.

## Changelog

### 1.0.0 (2025-12-31)
* Initial release
* Basic business hours functionality

## Support

**Free Support:**
- WordPress.org support forum
- Response within 48-72 hours

**Documentation:**
- [Full Documentation](https://kdt4u.com/smart-business-hours-cta)
- [Video Tutorials](https://kdt4u.com/smart-business-hours-cta)
- [FAQ](https://kdt4u.com/smart-business-hours-cta)

## Privacy & GDPR

This plugin:
- ✅ Does not collect personal data by default
- ✅ No external API calls
- ✅ No tracking cookies
- ✅ GDPR compliant

## Developer Documentation

### Hooks & Filters

```php
// Modify button output
add_filter('sbh_cta_button_html', 'my_custom_button', 10, 2);

// Modify business hours
add_filter('sbh_cta_business_hours', 'my_custom_hours', 10, 1);

// Add custom contact methods
add_filter('sbh_cta_contact_methods', 'my_contact_methods', 10, 1);

// Modify holiday list
add_filter('sbh_cta_holidays', 'my_holidays', 10, 1);
```

### Functions

```php
// Check if currently open
$is_open = sbh_cta_is_open();

// Get business hours
$hours = sbh_cta_get_hours();

// Get next opening time
$next_open = sbh_cta_next_opening();

// Check if holiday
$is_holiday = sbh_cta_is_holiday();
```

## Credits

Built with ❤️ for the WordPress community.

## License

This plugin is licensed under GPL v2 or later.

```
Smart Business Hours
Copyright (C) 2025 KDT4U Solutions

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

---

**Made with ❤️ by [Your Name](https://kdt4u.com)**

[Website](https://kdt4u.com) | [Documentation](https://kdt4u.com/smart-business-hours-cta) | [Support](https://kdt4u.com/support)
