WordPress.org

Forums

WooCommerce - excelling eCommerce
Hide prices for unlloged users - code. (4 posts)

  1. szzc
    Member
    Posted 1 year ago #

    Hi,
    Sorry about my English :)

    I found this code, its hidding prices and carts very well but the problem is:
    It should display - LOGIN OR REGISTER TO SEE PRICES
    It shows - LOGIN OR REGISTER TO SEE PRICES1111

    Do You have any ideas how to get rid with those 1111?
    Thanks a lot.

    add_filter('woocommerce_get_price_html','members_only_price');
    function members_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="' .get_permalink(woocommerce_get_page_id('myaccount')). '"> REGISTER</a> TO SEE PRICES'
    
    .remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart')
    .remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' , 11)
    .remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart' , 30)
    .remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' , 11)
    ;
    }

    http://wordpress.org/plugins/woocommerce/

  2. varktech.com
    Member
    Posted 1 year ago #

    more syntactically correct, untested...

    add_filter('woocommerce_get_price_html','members_only_price');
    function members_only_price($price){
    if(is_user_logged_in() ){
        return $price;
    }
    .remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart') ;
    .remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' , 11) ;
    .remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart' , 30) ;
    .remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' , 11) ;
    
    return '<a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">LOGIN</a> OR <a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '"> REGISTER</a> TO SEE PRICES';
    
    }
  3. szzc
    Member
    Posted 1 year ago #

    Hi, thanx for relpy.
    Unfortunatly now I have an empty screen on my wordpress so probably there is some mistake in Your code somewhere.

    I started to change my code (those parameters 11,30,11) and there are some results, ammount of (1) has changed, now i have only two (11), Do You know what are those parameters for exact?

    Thanks a lot.

  4. szzc
    Member
    Posted 1 year ago #

    Ok, I found a solution, I used this code below to hide prices and WooCommerce Email Inquiry & Cart Options LITE plugin(free) to hide cart, and its working good.

    add_filter('woocommerce_get_price_html','members_only_price');
    function members_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="' .get_permalink(woocommerce_get_page_id('myaccount')). '"> REGISTER</a> TO SEE PRICES'
    ;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.