How to Show Contact Form Only When Woocommerce Product is Out Of Stock?

By default your Woocommerce setup shows “Out of stock” message without any “add to cart” button or any other message. In this post I am showing you how to show a contact form only when your product status is “Out of stock”.

This is especially useful for the customers who would like to ask additional questions about the product itself or about whether or when it will be available.

How to Show Contact Form Only When Product is Out Of Stock?

Step 1: create a contact form

You can use whatever WordPress contact form plugin for that but keep in mind that If you would like your contact form entries to show you the product name and URL then you need your form to be able to add hidden fields and embed “post title” or “permalink” data. See the screenshot below.

In this tutorial I am using the Fluent Forms plugin which is a simple to use and offers lots of great features.

How to Show Contact Form Only When Woocommerce Product is Out Of Stock?

Step 2: Copy the code to the Code snippets code box

Code Snippets plugin is a free plugin which allows your to run PHP/HTML/CSS/JavaScript code snippets on your site without the need to modify functions.php. The plugin can be found here. Another option, paste the code to your child theme’s functions.php file.

/* Show contact form instead of "Out Of Stock" message */

add_action('woocommerce_single_product_summary', 'out_of_stock_show_form', 20);
function out_of_stock_show_form() {
    global $product;
    if(!$product->is_in_stock( )) {
        echo  '<div class="your-form">';
        echo  'Unfortunately this product is out of stock.<br>Contact us for more information';
        echo  do_shortcode('[your-shortcode]'); // Replace with your own contact form shortcode
        echo  '</div>';
/* This will show your contact form when the variation is out of stock */

add_filter( 'woocommerce_available_variation', 'variation_out_of_stock_show_form', 10, 3 );
function variation_out_of_stock_show_form( $data, $product, $variation ) {
    if( ! $data['is_in_stock'] )
        $data['availability_html'] = '<div class="your-form">';
        $data['availability_html'] .= 'Unfortunately this product is out of stock.<br>Contact us for more information';
        $data['availability_html'] .= do_shortcode('[your-shortcode]'); // Replace with your own contact form shortcode
        $data['availability_html'] .= '</div>';
    return $data;

Pay attention the line which contains [your-shortcode]. This is the place you should add your own contact form shortcode.

Video: How to Show Contact Form Only When Woocommerce Product is Out Of Stock?

Useful Tips

Here are some of my favorite Wordpress tools

Thank you for reading this article. I hope you found it helpful as you build your own websites and e-commerce sites. Here are some tools I use as a Wordpress developer and enthusiast that I hope you’ll also find helpful.

These are affiliate links, so if you do decide to use any of them, I’ll earn a commission and this helps me create these tutorials and make Youtube videos. But in all honesty, these are the exact tools that I use and recommend to everyone, even my friends and family.

Themes: For the last couple of years I have two go-to themes which I use for every kind of projects. Those two themes are Blocksy theme and Kadence Theme. On this site and my Youtube channel you’ll see a lot of tutorials I have made about them. If you would like to get a 10% discount for both of them then:

Code Snippets manager: WPCodeBox allows you to add code snippets to your site. Also, it allows you to build and manage your WordPress Code Snippets library in the cloud. You can grab it with the 20% discount here (SAVE 20% Coupon: WPSH20).

Contact forms: There are hundreds of contact forms out there but Fluent Forms is the one I like the most. If you need a 20% discount then use this link (save 20% coupon is WPSH20).

Gutenberg add-ons: If I need a good Gutenberg blocks add-on then Kadence Blocks is the one I have used the most. You’ll get 10% discount with the coupon SIMPLEHACKS here.

Website migration: While building a website you probably need a good plugin that can help you with the migration, backups, restoration and staging sites. Well, WpVivid is the one I have used for the last couple of years. If you use this link along with the WPSH20 coupon you’ll get 20% discount.

Woocommerce extensions: There are a bunch of Woocommerce extensions that I really like but the one that stands really out is Advanced Dynamic Pricing. Once again, you’ll get a 20% discount if you use this link here (save 20% coupon is WPSH20)

Web Hosting: If you would like to have a really fast and easy to use managed cloud hosting, then I recommend Verpex Hosting (see my review here). Btw, this site is hosted in Verpex.)

To see all my of most up-to-date recommendations, check out this resource that I made for you!

Do you want to thank me and buy me a beer?

Every donation is entirely welcome but NEVER required. Enjoy my work for free but if you would like to thank me and buy me a beer or two then you can use this form here below.

Donation Form (#2)

Best selling plugins

Janek T.
Janek T.

I am a Wordpress enthusiast who has been making websites since 2011. In this site I am offering simple to follow tips on how to use Wordpress and Woocommerce.
If you want to be the first to be notified about the new tutorials then please subscribe to my Youtube channel here
Follow me in Twitter here

Articles: 96