Restrict Product Attributes with login in Woocommerce

Restrict Product Attributes with login in Woocommerce

Sometimes most of the users want to restrict product attributes in woocommerce with login option, so below I will let you know how to restrict additional information tab in your ecommerce website . Sometime ecommerce website requires hide information of product attributes from public view (like competitors can use the information), while all the tab can be displayed after login :

Use below code to restrict your product attributes with login option for users

/** Restrict product attribute in shop page with login
 */

 add_filter( 'woocommerce_product_tabs', 'woo_vividtechno_login_tab', 9999 );
 
function woo_vividtechno_login_tab ( $tabs ) {
   if ( ! is_user_logged_in() ) { 
      $tabs = '<div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'Login to see prices', 'vividtechno' ) . '</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 );
   }
   return $tabs;
}

Copy this simple code and paste in function.php (at end of page) of child theme in woocommerce.

You will get the desired output

Regards

Vikas Mishra,
Vivid Techno

Leave a Comment

Your email address will not be published.

Shopping Cart