The holiday season is a great time to take a break and recharge. But what happens to your WooCommerce store while you’re away? To avoid confusion and ensure your customers know you’re closed, you can temporarily disable shopping features and display a clear holiday notice on your website. Here’s a simple PHP snippet that achieves this.
What Does This Snippet Do?
This snippet disables key WooCommerce functionalities, such as the “Add to Cart” button, the cart and checkout pages, and ensures customers are informed about your holiday schedule with a prominent notice.
You only need to change the warning text and add this hook to your child theme’s functions.php file.
add_action('woocommerce_after_shop_loop_item', function() {
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
}, 1);
add_action('woocommerce_single_product_summary', function() {
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
}, 1);
add_filter('woocommerce_is_purchasable', function($purchasable, $product) {
return false;
}, 10, 2);
add_action('template_redirect', function() {
if (is_cart() || is_checkout()) {
wp_safe_redirect(home_url());
exit;
}
});
add_action('wp_head', function() {
echo '<style>
.holiday-notice {
background-color: #ffcccc;
color: #333;
padding: 15px;
text-align: center;
font-size: 16px;
font-weight: bold;
}
</style>';
});
add_action('wp_body_open', function() {
echo '<div class="holiday-notice">We are closed for the Festive Season from the 13th Dec 2024 and will re-open on 6th January 2025. 🎅🎄</div>';
});
With this simple setup, you can enjoy your holiday season without worrying about your store. Let your customers know you’ll be back soon, and start the new year refreshed!
Leave a Reply