Hide product price
-
Hello,
It is possible to show my product price just after login?
Thank you
-
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);I placed that code on “functions.php” but don’t work :/
Paste your full code attempt.
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
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.
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
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.
The topic ‘Hide product price’ is closed to new replies.