Add Call for Price Button in WooCommerce

In this tutorial, we’ll demonstrate how to hide prices from both product archive pages and single product pages in WooCommerce. Instead of displaying prices, we’ll replace them with a “Call for Price” button, encouraging customers to make inquiries for pricing information.

/**
* Snippet Name:  Hide Price and add call for price button
* Snippet Author:  wpsnippets.dev
*/

// Hide prices from product loop items and single product pages
function wps_hide_price_from_loop( $price, $product ) {
    $price = '';
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'wps_hide_price_from_loop', 10, 2 );

// Remove default add to cart buttons
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

// Add "Call for Price" button to product archive page and single product pages
function wps_add_call_for_price_button() {
    echo '<a href="tel:2086465729" class="button call-for-price">' . __( 'Call for Price', 'textdomain' ) . '</a>';
}
add_action( 'woocommerce_after_shop_loop_item', 'wps_add_call_for_price_button', 9 );
add_action( 'woocommerce_single_product_summary', 'wps_add_call_for_price_button', 25, 0 );

Code Explanation

  • This code snippet first hooks into the woocommerce_get_price_html filter to hide prices by setting them to an empty string.
  • It then removes the default Add to Cart button from various product types using remove_action.
  • Finally, it adds a “Call for Price” button to both product loop items and single product pages using the wps_add_call_for_price_button function.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top