If you need to temporarily stop orders in your WooCommerce store—perhaps while making updates or complying with new regulations—you can easily disable the “Add to Cart” buttons and display a top bar notification informing customers that ordering is paused.
This tutorial shows you how to achieve this with a simple PHP snippet.
✅ Step 1: Disable Orders and Replace the “Add to Cart” Button
To stop orders, we’ll make all products unavailable for purchase and replace the “Add to Cart” button with a disabled button labeled “Temporarily Unavailable”.
Add the following code to your theme’s functions.php
file or to a custom plugin:
/* Stop orders */
// Disable purchasing but show a custom disabled button
add_filter( 'woocommerce_is_purchasable', '__return_false' );
add_filter( 'woocommerce_loop_add_to_cart_link', function( $button, $product ) {
return '<a class="button disabled" style="pointer-events:none; opacity:0.5;">Temporarily Unavailable</a>';
}, 10, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', function() {
return 'Temporarily Unavailable';
});
// Replace single product add to cart button
add_action( 'wp', function() {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', function() {
echo '<button class="button disabled" style="pointer-events:none; opacity:0.5;">Temporarily Unavailable</button>';
}, 30 );
});
This code ensures that customers see disabled buttons instead of being able to purchase products.
✅ Step 2: Add a Top Bar Notification
Next, let’s add a notification bar to the top of your site to inform customers why ordering is unavailable and when it will resume.
Add this code below the previous snippet in functions.php
:
// Add a top bar notification
add_action( 'wp_body_open', function() { ?>
<div style="
background-color: #f8d7da;
color: #721c24;
text-align: center;
padding: 15px;
font-size: 16px;
font-weight: 500;
border-bottom: 2px solid #f5c6cb;
z-index: 9999;
position: relative;
">
<h3 style="margin: 0 0 5px; font-size: 20px;">Site Under Maintenance</h3>
<p style="margin: 0;">
Dear customers, we are currently updating the site in accordance with new regulations.
Order processing is temporarily stopped.
We will resume <strong>Friday, August 1st, starting at 09:00</strong>.
Thank you for your understanding!
</p>
</div>
<?php
});
This bar will display at the top of your website and is styled to look like an alert notification.
⚠️ Important: Ensure wp_body_open
Works in Your Theme
The code above uses WordPress’s wp_body_open()
hook, which fires immediately after the opening <body>
tag. Most modern themes support this, but if your theme does not, you will need to manually add it.
- (1) Open your theme’s
header.php
file. - (2) Locate the opening
<body>
tag. - (3) Directly after
<body>
, insert this code:
<?php
if ( function_exists( 'wp_body_open' ) ) {
wp_body_open();
}
?>
This ensures that any content hooked into wp_body_open
(like our notification bar) will display properly.
🎯 Final Result
- All “Add to Cart” buttons are disabled and replaced with “Temporarily Unavailable”.
- A top bar notification appears sitewide, informing customers of the maintenance.
- Orders are fully blocked until you’re ready to re-enable them.
When your site is ready to take orders again, simply remove these snippets or comment them out.