Better Woocommerce Out of Stock Message

With this snippet, I’ll show you how to display a better Woocommerce out of stock message which will hopefully result in more sales and happier customers. Unlike most other turorials which simply modify the message

that appears, this snippet will promote content which is currently available without breaking the look and feel of the site. I’ve been using this method for quite a while with great success and highly recommend it.

Before we get too far into this post I should make a few points. For best results, it’s highly recommended that you segment your content into relevant categories and tags. This default snippet will make use of the related products shortcode, but you can substitute the related with any other Woocommerce shortcode that you want to use. You can also tie this in with our snippet to change the actual out of stock message text for an even better buyer experience

a better Woocommerce out of stock message

The code snippet for a better Woocommerce out of stock message

/*
** Snippet Out of stock up sell
** source code https://wcsuccessacademy.com/?p=435
** Author John Cook
** Tested with WooCommerce 3.3.3
*/
add_action( 'woocommerce_before_single_product_summary', 'my_related_out_of_stock', 15);
function my_related_out_of_stock () {
  global $product;
  $availability = $product->get_availability();
  
  /*check if availability in the array = string 'Out of Stock'
  **if so display on page.
  */
  if ( $availability['availability'] == 'Out of stock') {
    echo '<h2 style="text-align: center; text-decoration: underline; font-size: 2em;">This item is currently out of stock</h2>';
    echo '<h3 style="text-align: center;">Perhaps one of the following may interest you?</h3>';
    echo do_shortcode( '[related_products]' );
  }
}

Where does this snippet go?

Place this code snippet at the end of your child themes functions.php file just before the closing ?>(if your theme has it). Alternatively, and recommended, place the code snippet into a functions plugin, such as one on this list. The use of a functions plugin will ensure that changes are kept across themes and updates.

You can further modify the code using different shortcodes and css to get a better look and more relevant results. I do honestly believe that this is a a better Woocommerce out of stock message than the packaged one or any modification of it.

Did it work?

Let me know in the comments if it worked for you. With a bit of styling and some modifications to the code you can extend the use and upsell potential of this code snippet.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Scroll to Top