This snippet removes all instances of the Add To Cart button whatever the product type (Simple, Grouped, Variable, External) then displays a new button on both the product archive loop items and the single product template which says “Call for a price”. This button, if clicked, is hyperlinked to a custom telephone number which will be called on click. This guide is useful if you don’t want users to see prices and require them to call you instead of adding products to cart.
/**
* Snippet Name: WooCommerce Call For A Price
* Snippet Author: ecommercehints.com
*/
// First, remove all instances of the add to cart button
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 );
// Show a new 'Call for a price' button on the product archive loop items
function ecommercehints_call_for_a_price_on_product_archive_loop() {
echo 'Call for a price'; // Telephone number and button text
};
add_action ('woocommerce_after_shop_loop_item', 'ecommercehints_call_for_a_price_on_product_archive_loop', 10, 0);
// Show a new 'Call for a price' button on the single product template
function ecommercehints_call_for_a_price_on_single_product_template() {
echo 'Call for a price'; // Telephone number and button text
};
add_action ('woocommerce_single_product_summary', 'ecommercehints_call_for_a_price_on_single_product_template', 25, 0);