Hide Price and Add To Cart button from WooCommerce Products

In this simple tutorial I shall show you how you will hide the product price and add to cart button without editing the WooCommerce plugin.

Following steps will work with any themes.

Creates New PHP file

At first we shall create a new file “no-add-to-cart-button.php” and save into yourthemefolder/woocommerce folder. If woocommerce folder is not available in your theme folder, you will create it. Here is the code of that PHP file:

Scenario 1: Hiding Price & Button For All Customers.

Open your functions.php file and drop the following code at end of the file.

/**
 * Hides the price and add-to-cart button from the product
 * 
 * @copyright paulchinmoy.com
 * @author Paul Chinmoy
 **/
add_action( 'init', 'paulc_hide_price_add_to_cart_button', 1000 );
function paulc_hide_price_add_to_cart_button() {
	add_filter( 'woocommerce_get_price_html', '__return_false' );
    add_filter( 'woocommerce_loop_add_to_cart_link', '__return_null' );
    add_filter( 'wc_get_template', 'paulc_wc_get_template', 90, 2 );
}

/**
 * Hides the add-to-cart button from the single product page
 * 
 * @copyright paulchinmoy.com
 * @author Paul Chinmoy
 **/
function paulc_wc_get_template( $located, $template_name ) {
	$new_path = get_stylesheet_directory_uri() . '/woocommerce/no-add-to-cart-button.php';
    $templates = array(
    	'single-product/add-to-cart/simple.php',
        'single-product/add-to-cart/grouped.php',
        'single-product/add-to-cart/variable.php',
        'single-product/add-to-cart/external.php'
    );
    
    if( in_array( $template_name, $templates ) ) {
    	return $new_path;
    }
    
    return $located;
}

Scenario 2: Hiding Price & Button Only For Logged Out Customers

Open your functions.php file and drop the following code at end of the file.

/**
 * Hides the price and add-to-cart button from the product
 * 
 * @copyright paulchinmoy.com
 * @author Paul Chinmoy
 **/
add_action( 'init', 'paulc_hide_price_add_to_cart_button', 1000 );
function paulc_hide_price_add_to_cart_button() {
	if( is_user_logged_in() )
    	return;
        
	add_filter( 'woocommerce_get_price_html', '__return_false' );
    add_filter( 'woocommerce_loop_add_to_cart_link', '__return_null' );
    add_filter( 'wc_get_template', 'paulc_wc_get_template', 90, 2 );
}

/**
 * Hides the add-to-cart button from the single product page
 * 
 * @copyright paulchinmoy.com
 * @author Paul Chinmoy
 **/
function paulc_wc_get_template( $located, $template_name ) {
	$new_path = get_stylesheet_directory_uri() . '/woocommerce/no-add-to-cart-button.php';
    $templates = array(
    	'single-product/add-to-cart/simple.php',
        'single-product/add-to-cart/grouped.php',
        'single-product/add-to-cart/variable.php',
        'single-product/add-to-cart/external.php'
    );
    
    if( in_array( $template_name, $templates ) ) {
    	return $new_path;
    }
    
    return $located;
}

Scenario 3: Hiding Only Add To Cart Button

Open your functions.php file and drop the following code at end of the file.

/**
 * Hides the add-to-cart button from the product
 * 
 * @copyright paulchinmoy.com
 * @author Paul Chinmoy
 **/
add_action( 'init', 'paulc_hide_add_to_cart_button', 1000 );
function paulc_hide_add_to_cart_button() {
    add_filter( 'woocommerce_loop_add_to_cart_link', '__return_null' );
    add_filter( 'wc_get_template', 'paulc_wc_get_template', 90, 2 );
}

/**
 * Hides the add-to-cart button from the single product page
 * 
 * @copyright paulchinmoy.com
 * @author Paul Chinmoy
 **/
function paulc_wc_get_template( $located, $template_name ) {
	$new_path = get_stylesheet_directory_uri() . '/woocommerce/no-add-to-cart-button.php';
    $templates = array(
    	'single-product/add-to-cart/simple.php',
        'single-product/add-to-cart/grouped.php',
        'single-product/add-to-cart/variable.php',
        'single-product/add-to-cart/external.php'
    );
    
    if( in_array( $template_name, $templates ) ) {
    	return $new_path;
    }
    
    return $located;
}
This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.