How to Hide Price and add to cart to non-register members in Woocommerce | themelocation

How to Hide Price and add to cart to non-register members in Woocommerce

In this tutorial we’ll learn how to hide the prices and add to cart button to non-registered members. The process is simple enough we can achieve this by using one of woocommerce’s defined filter and by imposing a check to add that filter.

Initially the shop and single product page will look something like this:

woocommercewoocommerceHere add to cart button and prices are visible.

Now, if you place the following lines of code at the end of functions.php it will enable the desired functionality.

add_filter('woocommerce_get_price_html','members_only_price');

functionmembers_only_price($price){

if(is_user_logged_in() ){

return $price;

}

else return '<a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Login</a> or <a href="'.site_url('/wp-login.php?action=register&redirect_to=' . get_permalink()).'">Register</a> to see price!';

}

You can find the functions.php file here:

woocommerceNow, place the code save the file and refresh your page.

You’ll see the add to cart button and prices removed and it will add login and register links instead.

Now your shop page and single product page will look something like this.

woocommercewoocommerce

That is it!

No comments yet.

Leave a Reply