Hide Price and Add to Cart Button in WooCommerce Shop
Code Snippet to hide product prices and add to cart button in WooCommerce Shop without using a plugin. The prices and add to cart button will only be visible once the user is logged in.
Copy the code below and paste it in functions.php
add_filter( 'woocommerce_get_price_html', 'wehelpcode_hide_price_addcart_not_logged_in', 9999, 2 );
function wehelpcode_hide_price_addcart_not_logged_in( $price, $product ) { if ( ! is_user_logged_in() )
{
$price = ' <div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">
' . __( 'Available for registered users', 'wehelpcode' ) . '</a></div>';
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_filter( 'woocommerce_is_purchasable', '__return_false' );
}
return $price;
}