You might want to show a “POA” price and/or a “Call for Price” button when you have a product with an empty price.
Many businesses require this, mostly real estate and wholesalers. So let’s see how it’s done 🙂
PHP Snippet: Display “POA” & Enquiry Button If Price Empty @ WooCommerce Single Product Page
Before taking a look at the snippet, make sure your “POA” product has no price (regular and sale price). Also, please reference to this other article if you want to add some Javascript to show/hide a Contact Form 7: https://businessbloomer.com/woocommerce-show-inquiry-form-single-product-page-cf7/
/**
* @snippet Display "POA" for blank price products @ WooCommerce Single Product
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 3.8
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_empty_price_html', 'bbloomer_poa_and_enquiry_cf7_woocommerce' );
function bbloomer_poa_and_enquiry_cf7_woocommerce() {
$html = '<div class="poa">POA</div>';
$html .= '<button type="submit" id="trigger_cf" class="single_add_to_cart_button button alt"> Request Price Now </button>';
$html .= '<div id="product_inq" style="display:none">';
$html .= do_shortcode('[paste_your_contact_form_7_shortcode_here]');
$html .= '</div>';
return $html;
}
I’ve packaged something like this up into a plugin, as I needed the exact same kind of functionality on a client site recently. They sell a lot of heavy duty equipment that requires installation: https://chrisjallen.com/2019/05/28/woo-custom-empty-price-add-your-own-call-to-action-when-your-product-has-no-price/
Nice!
Can the code $html .= do_shortcode(‘[paste_your_contact_form_7_shortcode_here]’); be amended to a phone line like:
$html .= do_shortcode(‘<a href="tel:[$phone];"Call to Order‘); or something to that effect. Forgive my unrelated code entry syntax.
Then, on the single product admin page, have an additional field to put in a phone number in this type of format: +5551234567
That way if a different Dept or Section for each individual product would be called, instead of a single generic number. Make sense?
Hello Roberta, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hi,
I have just inserted your code, add a Contact 7 form and then went to the front end and clicked on ‘Request Price’ but nothing happens.
Contact form short code: contact-form-7 id=”63″ title=”Contact form 1″ and I tried contact-form-7 id=”63″
I have obviously pasted something wrong! 🙂
Hey Rob, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R
Hi Rodolfo,
Thanks for the response. I am not sure what you mean about customerisation as there isn’t any.
I have just switched to 2015 theme and it still doesn’t work.
see here: https://synaxissolutions.co.uk/2018/product/testing-testing/
AS I said maybe I have not completed what is required, but I have pasted the coding into functions.php of 2015
See here: https://screencast.com/t/PpV3zWH5Np7c
and I have all plugins deactivated,. see here: https://screencast.com/t/MDFsnpIu2bT
If it all still works, can you tell me under which theme it works, and I wil debug from there.
Thanks
Hi,
I have tested further and managed to get the ‘Requset More detail’ working, but now the ‘Request More Detail’ button does not disappear when I add in price.
See here: https://synaxissolutions.co.uk/2018/product/epilson-e9-83-twin-controls/
has price and request more details. See here:https://screencast.com/t/3t7YMofow
Maybe I have misunderstood the functions.php?
Hey Rob, this should work. Sorry but I can’t provide complementary troubleshooting here via the blog comments – thanks for your understanding 🙂
Is there a way to restrict this to alter just the price of the product on the product page itself? At present, it shows for the price on related products below the product page and on recently viewed products in the sidebar also
I’ve tried using “if ( is_product() ) {…” and while this stops the button appearing on the shop / category pages, it displays everywhere (active product, related and recent) once in a product page
Thanks in advance
Hiya Conor, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Love the article, thanks it helps a lot, my only issue is that i dont use contact form 7, i use Caldera Forms and the short code does not work. any adjustment in code to achieve this?
Hey Wesley, if you change the shortcode it should work out of the box. Make sure the shortcode is written properly and that you keep the single quotes before and after.
Hi Rodolfo, i got your code right, but the only problem is that it shows on pages that have prices too. I have not adjusted your code, other than the label and the short code. So even if there is a price, it still shows up.
Never mind, i am being a tonsil 🙂 I didnt change the action name.
But it still shows up on the category page, with the button and does nothing when you click on it. I wish i had a programming mind like yours 🙁
hey Wesley, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂
Thanks a lot Rodolfo, happens to be just what I was looking for today!
Brilliant 🙂
Hello,
I’m currently working on an ecommerce for a client, using the Woocommerce Storefront theme (editing on child theme version). Right now, I’m trying to display text instead of not showing the product price when left blank. I’ve been looking for a solution to this problem for a while. Im happy I found the code you’ve provided, however no changes or error appeared on the website. Any recommendations?
Hey Allegra, thanks for your comment! This should work when the price is left blank – you have “blank” prices or “zero” prices?
Right now I have some products with and without pricing. The products without pricing are left blank.
Can you try switching to “Twentyseventeen” theme and let me know if the snippet works in that case?
Hello Rodolfo,
We are also using this snippet.
Do you have an example ‘code’ to disable the buttons on the shop pages?
We don’t know how to complete this code.
Also, we integrated a Contact Form 7.
The title of the product is showing in the ‘subject’ field.
But in this subject field, there is html code showing. > –
Anyway we can hide this? Besides deleting this from every product.
Example: Josval – FILTRO FES-22000 – Microfilter 22000 l/m
Hey Luuk, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R
Hi Rodolfo,
I added this snippet and all works fine. Except the “POA” and “Request Price” button is also showing on the shop pages?
Is there any way to exclude this from showing on the pages?
Hey Cathy 🙂 Yes, of course. Inside the function, use:
This is called “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/