This simple Woocommerce WordPress script can be modified for a variety of purposes, such adding in Country specific currency symbols like AUD, USD, or appending additional information. The example below shows login or register links until they are logged in, and when logged in will see the normal price as listed.add_filter(‘woocommerce_get_price_html’,’members_only_pricing’);

  1. function members_only_pricing($price){
  2.  
  3. if(is_user_logged_in() ){
  4. return $price;
  5. }
  6.  
  7. else {
  8. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
  9. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
  10. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
  11. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
  12. return '<a href="'.site_url('/wp-login.php?action=register&redirect_to=' . get_permalink()).'">Login</a> to view our prices.'; }
  13.  
  14. }

Place in your themes functions.php – Let me know how it goes.

One comment on “Woocommerce Hide Price until User Logged in”

  • Danny Russell (author)

    How would you do this to hide pricing etc on variable products?

Leave a Reply

Your email address will not be published. Required fields are marked *