![](https://webreach.se/wp-content/uploads/2023/11/pexels-pixabay-270360-1024x682.jpg)
How to Disable the Checkout Button When Your Store is Closed
In this article, I’m going to show you how to make your WooCommerce store’s checkout button inactive when your store is closed. This ensures that customers can’t place orders during off-hours, providing you better control over your store operations. Let’s dive right in!
Step 1: Create the HTML Structure
First, you need to create some HTML. If you’re using Elementor, you can simply put an HTML element into your page. If you’re not using Elementor, add the HTML in a way that suits your setup.
Step 2: Insert the Script
In the HTML section, you’ll paste a script that handles the enabling and disabling of the checkout button based on your store’s operating hours. Here’s a sample script for reference:
Step 3: Customize the Script
Store Hours
In the script, you can see the opening and closing hours for each day of the week. Modify these values to match your store’s schedule:
var openingTimes = {
0: { open: 12, close: 21 }, // Sunday
1: { open: 11, close: 21 }, // Monday
2: { open: 11, close: 21 }, // Tuesday
3: { open: 11, close: 21 }, // Wednesday
4: { open: 11, close: 21 }, // Thursday
5: { open: 11, close: 21 }, // Friday
6: { open: 12, close: 21 } // Saturday
};
Button Selector
Ensure you target the correct checkout button by inspecting the element on your site. Right-click the checkout button, select ”Inspect”, and find its class. Replace .button.alt
in the script with the correct class:
var checkoutButton = document.querySelector('.button.alt');
Final Notes
- Ensure Specificity: Make sure the class you target is specific to avoid affecting other elements.
- Testing: Test the script during both open and closed hours to ensure it works as expected.
- Adaptation: Adapt the script to your needs, especially if you’re using a different checkout system or theme.
That’s it! By following these steps, you’ll have a checkout button that only functions during your store’s operating hours, preventing orders from being placed when your store is closed. Happy hacking.