WordPress.org

Support

Support » Plugins and Hacks » WooCommerce » Hide prices for unlloged users – code.

Hide prices for unlloged users – code.

  • 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/

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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';
    
    }

    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.

    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'
    ;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide prices for unlloged users – code.’ is closed to new replies.
Skip to toolbar