AI Verified

Name

Show prices only for logged in users

About

This code ensures that the prices in your store are only displayed for registered and logged in users. Visitors can not see prices.

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

jbeer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

14/11/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Show prices only for logged in users

 
                    
1if (!function_exists( 'evolution_hide_price_add_cart_not_logged_in' ) ) :
2 /**
3 * Preise nur für registrierte und eingeloggte User anzeigen
4 */
5 
6function evolution_hide_price_add_cart_not_logged_in() {
7 
8if ( !is_user_logged_in() ) {
9 
10 remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
11 remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
12 remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
13 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
14 add_action( 'woocommerce_single_product_summary', 'print_login_to_see', 31 );
15 add_action( 'woocommerce_after_shop_loop_item', 'print_login_to_see', 11 );
16 }
17}
18add_action('init', 'evolution_hide_price_add_cart_not_logged_in');
19 
20/**
21 * Zeigt einen Login-Link mit Message an
22 */
23function evolution_print_login_to_see() {
24 
25echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Logge Dich ein, um die Preise zu sehen', 'theme_name') . '</a>';
26 
27}
28endif;

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

Unverified

0

Customize CSS text style COUPON

Added: 1 year ago

Last Updated: 1 year ago

Make customize CSS text style "Coupon" on your Check out page.

WooCommerce

AI Verified

3

Confirm Password Field in Woocommerce

Added: 1 year ago

Last Updated: 1 day ago

WooCommerce

AI Verified

1

WooCommerce Show Custom Content Above Product Name

Added: 1 year ago

Last Updated: 1 day ago

This quick guide shows you how to display custom content above the product title on the single product template using the woocommerce_single_product_summary hook. You may need to tweak the priority nu...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

3

Confirm Password Field in Woocommerce

Added: 1 year ago

Last Updated: 1 day ago

WooCommerce

AI Verified

3

Redirect customers to own thank-you page after order

Added: 1 year ago

Last Updated: 1 day ago

You may want to redirect your customers to a custom thank you page after they place an order. You can do that with the following WooCommerce snippet

WooCommerce

AI Verified

2

Bypass logout confirmation.

Added: 1 year ago

Last Updated: 1 month ago