Some WooCommerce products need a custom quote before a customer can place an order. This is common for wholesale items, bulk purchases, made-to-order products, and products that require special customization. For these products, displaying a fixed price may not be suitable.
You can replace the regular product price and Add to Cart button with a contact button that directs customers to your contact page. They can then ask about pricing, request a quote, or discuss their requirements before placing an order.
WooCommerce does not provide a built-in setting to replace the product price with a contact button. However, you can make this change with a PHP snippet. In this guide, you will learn how to hide the price and Add to Cart button on single product pages and display a custom contact button without installing a dedicated inquiry plugin.
What This WooCommerce Snippet Does
- Hides the product price on individual product pages.
- Removes the default Add to Cart button.
- Displays a custom contact button in the product summary.
- Links customers to your contact page.
- Works without a dedicated product inquiry plugin.
- Can be adapted to target selected products.
WooCommerce PHP Snippet to Replace Price with Contact Button
The following PHP snippet removes the standard WooCommerce price and Add to Cart button from single product pages. It then adds a Contact Us for Pricing button in the product summary area.
/**
* Replace WooCommerce Product Price with Contact Button
*/
add_action( 'wp', 'gh_replace_price_with_contact_button' );
function gh_replace_price_with_contact_button() {
// Apply changes only to single product pages
if ( ! is_product() ) {
return;
}
// Remove the product price
remove_action(
'woocommerce_single_product_summary',
'woocommerce_template_single_price',
10
);
// Remove the Add to Cart button
remove_action(
'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart',
30
);
// Add the contact button
add_action(
'woocommerce_single_product_summary',
'gh_display_product_contact_button',
30
);
}
function gh_display_product_contact_button() {
$contact_url = home_url( '/contact/' );
echo '<a href="' . esc_url( $contact_url ) . '" class="button alt">Contact Us for Pricing</a>';
}
Important: This snippet expects your contact page to use the /contact/ URL. If your page uses a different URL, change the path in the home_url() function.
The code targets standard single product pages. It does not automatically hide prices on shop pages, category archives, widgets, or custom product layouts.
How the WooCommerce Contact Button Code Works
The snippet uses WordPress and WooCommerce hooks to change the product page layout.
is_product()checks whether the current page is an individual WooCommerce product.remove_action()removes the default product price and Add to Cart button from the product summary.add_action()adds the custom contact button in the same general area.home_url()creates the link to your contact page.esc_url()helps ensure the link is safely output in the page HTML.
When a customer clicks the contact button, they are redirected to your contact page. Add a working contact form to that page so customers can provide their details, identify the product, and explain what pricing information they need.
How to Add the PHP Code to WooCommerce
Step 1: Back Up Your Website
Create a backup before changing PHP code. If your hosting plan provides a staging site, test the snippet there before adding it to your live store.
Step 2: Open Your Child Theme’s functions.php File
In your WordPress dashboard, go to Appearance and then Theme File Editor, if available. Open the functions.php file for your child theme.
You can also edit the file through your hosting control panel or a secure file manager. A child theme is preferable to the parent theme because updates to the parent theme can overwrite custom changes.
Step 3: Add the Snippet
Paste the code at the end of your child theme’s functions.php file. If the file already starts with <?php, do not add another opening PHP tag.
Alternatively, use a PHP code snippets plugin and follow its instructions for adding and activating the code. Do not run the same snippet in both your theme and a snippets plugin.
Step 4: Test the Product Page
Open a single product page and check that the price and Add to Cart button are hidden. Confirm that the Contact Us for Pricing button appears and links to the correct contact page.
Submit a test inquiry through your contact form to make sure messages are being received. Also check the page on mobile devices and in a different browser if possible.
How to Show the Contact Button for Selected Products Only
You may want to hide prices for selected products while allowing customers to purchase other products normally. You can do this by checking the product ID before removing the price and Add to Cart button.
Add the following condition inside gh_replace_price_with_contact_button(), immediately after the is_product() check and before the remove_action() calls.
$product_id = get_queried_object_id();
if ( ! in_array( $product_id, array( 123, 456 ), true ) ) {
return;
}
Replace 123 and 456 with the IDs of the products that should use the contact button. Keep this condition before the code that removes the price and Add to Cart button.
Only the selected product pages will receive the change. Other products will retain their standard WooCommerce price and purchase button.
How to Change the Contact Button Text
You can change the button label to suit your store. For example, use Request a Quote for products that need a custom quotation, or Ask for Pricing for products with prices that depend on customer requirements.
In the gh_display_product_contact_button() function, replace the existing button text with your preferred label. For example:
echo '<a href="'. esc_url($contact_url). '" class="button alt">Request a Quote</a>';
The button will keep its link and CSS classes while displaying the updated text.
Important Things to Know Before Using This Snippet
This code changes the standard single product page summary. It does not automatically remove prices from product archives, category pages, widgets, quick-view windows, or custom templates. Those areas may need separate changes.
Hiding the price and Add to Cart button does not completely prevent a product from being purchased through other routes. If customers must request a quote before buying, you may also need to restrict purchasing for those products.
If your store uses variable products, subscriptions, a custom theme, or a page builder, test the code carefully. These setups may use different product templates or additional hooks.
For more information about WooCommerce hooks, read the official WooCommerce guide to actions and filters.
Frequently Asked Questions
Can I replace the WooCommerce product price without a plugin?
Yes. You can use a PHP snippet in your child theme’s functions.php file or manage it with a code snippets plugin. A dedicated product inquiry plugin is not required for this basic change.
Does this snippet create a contact form?
No. It only adds a button that links to your contact page. You must create and test the contact form separately.
Can I hide the Add to Cart button but keep the product price?
Yes. Remove the price-related remove_action() call from the snippet and keep the code that removes the Add to Cart button and adds the contact button.
Can I use this code for wholesale products?
Yes. This approach can work for wholesale items, bulk orders, custom-made products, and other products that need a price quote before purchase.
Will this code hide the price across the entire website?
No. It targets standard single product pages. Prices displayed on shop pages, category pages, widgets, or custom templates may remain visible.
Final Thoughts
Replacing the WooCommerce product price and Add to Cart button with a contact button is useful for stores that handle custom quotations, wholesale orders, or products with flexible pricing. A short PHP snippet lets you make this change without installing a dedicated inquiry plugin.
Test the code on a staging site before using it on your live store. Check the contact link and form, and add product-specific conditions if only certain products should require a quote.