Hide Prices
-
Hi,
I’m trying to make my WordPress ecommerce website set up so that logged out users cannot see pricing, but they can still see variations of the product. I have found 2 bits of code that don’t completely solve this problem.
This code hides the price but when they click a variant it still shows the add to cart button and they can see the price in the cart:
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="'.site_url('/wp-login.php?action=register&redirect_to=' . get_permalink()).'">Register</a> to see price!'; }This bit of code hides the add to cart and price, but doesn’t show the color options/variations:
add_action('after_setup_theme','activate_filter') ; function activate_filter(){ add_filter('woocommerce_get_price_html', 'show_price_logged'); } function show_price_logged($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 '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>'; } }Does anyone know a way to manipulate one of these bits of code or know of a code that does this? I’m struggling to find a solution.
The topic ‘Hide Prices’ is closed to new replies.