Advertisement
businessdad

WooCommerce - Hide prices for guests

Aug 16th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. /**
  2.  * Hide prices and "add to cart" action for guests.
  3.  * Need help customising the code for your need? Hire us on Codeable: https://aelia.co/hire_us
  4.  *
  5.  * @author Aelia
  6.  * @link https://aelia.co
  7.  */
  8. function aelia_hide_prices_for_guests() {
  9.   if(!is_user_logged_in()) {      
  10.     // If user is not logged in, hide the prices on the catalogue and product pages
  11.     remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
  12.     remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
  13.  
  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.   }
  17. }
  18. add_action('init', 'aelia_hide_prices_for_guests');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement