search ]

Show Prices Only to Logged-In Users in WooCommerce

There are many situations where you want to hide prices in your WooCommerce store and show them only to certain users by some criterion. WooCommerce has a filter called woocommerce_get_price_html that makes this easy:

add_filter( 'woocommerce_get_price_html', function( $price ) {
	if ( is_user_logged_in() ) return $price;
	return '';
} );

In the code above (add to functions.php) we used a condition that if the user is not logged in, prices will not be shown in the store. You can of course use any condition you choose.

For more WooCommerce customization, see Mastering WooCommerce Hooks.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo