Viewing 8 replies - 1 through 8 (of 8 total)
  • Google is everyone’s friend 🙂 The solution mentioned on that link works only for simple products, if you have variable products just add the following line of code to that snippet.

    add_filter('woocommerce_variable_price_html', 'members_only_price', 10, 2);

    http://stackoverflow.com/questions/22459559/how-to-show-price-and-variation-price-for-logged-in-users-only-in-woocommerce

    Thread Starter fsilvalvm

    (@fsilvalvm)

    I placed that code on “functions.php” but don’t work :/

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Paste your full code attempt.

    Thread Starter fsilvalvm

    (@fsilvalvm)

    I tried with this code:
    add_filter('woocommerce_variable_price_html', 'members_only_price', 10, 2);

    and

    add_filter('woocommerce_get_price_html','members_only_price');
    
    function members_only_price($price){
    
    if(is_user_logged_in() ){
    return $price;
    }
    
    else {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    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', 10 );
    return 'Only <a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Registered Users</a> are able to view pricing.';
      }
    
    }

    but i got the same problem

    Plugin Contributor Mike Jolley

    (@mikejolley)

    The remove actions should not be within that function – they should be called earlier, outside of the function but wrapped in another is_user_logged_in check.

    Thread Starter fsilvalvm

    (@fsilvalvm)

    ok, it’s working thank you 🙂

    just one more thing, which table are saved the products?

    Share you code back here for future visitors.

    Products is custom post type, the data is stored in wp_posts and wp_postmeta

    Thread Starter fsilvalvm

    (@fsilvalvm)

    add_filter('woocommerce_get_price_html','hide_price');
    
    function hide_price($price){
    
    if(is_user_logged_in() ){
    return $price;
    }
    
    else {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    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', 10 );
    return 'Only <a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Registered Users</a> are able to view pricing.';
      }
    
    }

    it’s the same code but you have to logout from WP admin panel to see it working.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Hide product price’ is closed to new replies.