Advertisement

Imagine you have some special individual products on your WooCommerce store where you do not want to show the price to the public visitor. Probably you want your interested customers to contact you to get more information about the price. In this case I recommend you to do the following: WooCommerce: Custom Text if no Price
Modify your WooCommerce store thus it is at least displaying the text “Price on Inquiry”. I also suggest you to combine this with the following modification: Include a contact form directly at the product page. In the form, you can define that the exact URL will be included into the email. So you can create the connection between product page and inquiry. I will create an article how to do that in the next time.

But let’s stay for now at the function to modify the “Price on Inquiry” text. In order to keep your changes when updating your theme, I recommend you to create a child theme in case you do not have one yet. It is a very simple process and you can look it up here:
https://www.wpbeginner.com/wp-themes/how-to-create-a-wordpress-child-theme-video/

Advertisement

At the child theme you can include this code snippet in your functions.php file, which you may need to create in case you just created your new child theme. The code snippet itself is very simple, if the product price is equal to 0 or ” it will return a line of HTML which you can customize as you need it. I found the necessary information at the following site:
https://businessbloomer.com/

// Inquiry link if no price available

function add_inquiry_link_instead_price( $price, $product ) {

    if ( '' === $product->get_price() || 0 == $product->get_price() ) {

        return '<span class="price_on_inquiry">Price on Inquiry</span>';

    }

    return $price;

}

add_filter( 'woocommerce_get_price_html', 'add_inquiry_link_instead_price', 100, 2 );

WooCommerce: Custom Text if no Price
For other customization to your WordPress site, check out my category

Advertisement

LEAVE A REPLY

Please enter your comment!
Please enter your name here