Hello WordPress Masters,

I have a WooCommerce issue I need help with. I'm more of a front-end developer slash designer, and my attempts at solving this have been fruitless so far.

What I'm trying to do: Whenever a product is out of stock, I want to display a custom out of stock message (done) and a contact form below it (need help).

I use Contact Form 7 and have a shortcode I would normally insert. While I've figured out how to insert it with echo do_shortcode('[name_of_shortcode]'); I don't know how to make it appear only on products which are out of stock.

Here's the custom code I currently use in my child-theme's function.php file:

add_filter('woocommerce_get_availability', 'availability_filter_func');
function availability_filter_func($availability)
$availability['availability'] = str_ireplace('Out of stock', 'This class is not currently available at a scheduled time, but is instead being scheduled in response to customer interest.  If you are interested in taking this class, please provide your contact information and we will reach out to with dates that are currently under consideration.', $availability['availability']);
return $availability;

As you can see, I was able to change the custom out of stock message but I have no clue how to call a shortcode after the message.

WordPress and WooCommerce Gurus, what should I do?

Thank you for your assistance and for taking time to educate me!



1 Answer 1


You need to use the hooks WooCommerce provides. I would try it like following (untested):

add_action('woocommerce_single_product_summary', 'add_contact_form', 20);

function add_contact_form() {
    global $product;
    if(!$product->is_in_stock( )) {
       echo do_shortcode('[name_of_shortcode]');
  • Thank you Pascal! This solved my issue! Thank you x1000 :) You made my day!
    – vervex
    Commented Jul 31, 2017 at 11:31
  • Glad I could help :) Commented Jul 31, 2017 at 14:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.