Skip to content
Advertisement

Add a Contact Form to “Out of Stock” product Variations in WooCommerce

I have successfully added a contact form to a product if it is Out of Stock using

JavaScript

But I also want to add the same form if a products variation is Out of Stock too. Just unsure as to which hook I can use to tie it in to the Out of Stock message for that variation… I feel like it may be something to do with line 20 of woocommerce/single-product/add-to-cart/variation.php

JavaScript

But am getting a bit lost TBH.

I can change the text that is diaplyed for both simple products and those with variations by using

JavaScript

But if I try and add the Form Shortcode or other HTML, like an iFrame, it is stripped out and does not render.

Advertisement

Answer

The following code will add a contact form to a selected out of stock product variation:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here


So you will need to tweak your existing code as follow:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement