rajudhaka

Login to see pricing Woocommerce

Apr 20th, 2020
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. /**
  2.  * @snippet       Hide Price & Add to Cart for Logged Out Users
  3.  * @how-to        Get CustomizeWoo.com FREE
  4.  * @sourcecode    https://businessbloomer.com/?p=299
  5.  * @compatible    WooCommerce 3.6.2
  6.  * @donate $9     https://businessbloomer.com/bloomer-armada/
  7.  */
  8.  
  9. add_action( 'init', 'bbloomer_hide_price_add_cart_not_logged_in' );
  10.  
  11. function bbloomer_hide_price_add_cart_not_logged_in() {  
  12. if ( ! is_user_logged_in() ) {      
  13.  remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
  14.  remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
  15.  remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
  16.  remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );  
  17.  add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
  18.  add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
  19. }
  20. }
  21.  
  22. function bbloomer_print_login_to_see() {
  23. echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>';
  24. }
Advertisement
Add Comment
Please, Sign In to add comment