Skip to content

Commit 8dc44ec

Browse files
Create hide-prices-unless-user-is-logged-in.txt
1 parent 0bdbe3f commit 8dc44ec

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Hide prices unless user is logged in
2+
add_filter('woocommerce_get_price_html', 'hide_price_for_guests', 10, 2);
3+
add_filter('woocommerce_cart_item_price', 'hide_price_for_guests', 10, 2);
4+
add_filter('woocommerce_cart_item_subtotal', 'hide_price_for_guests', 10, 2);
5+
6+
function hide_price_for_guests($price, $product) {
7+
if (!is_user_logged_in()) {
8+
return '<span class="login-to-see-price">Login to see price</span>';
9+
}
10+
return $price;
11+
}
12+
13+
// Optional: Hide add to cart buttons for guests
14+
add_filter('woocommerce_is_purchasable', 'disable_purchase_for_guests', 10, 2);
15+
16+
function disable_purchase_for_guests($purchasable, $product) {
17+
if (!is_user_logged_in()) {
18+
return false;
19+
}
20+
return $purchasable;
21+
}

0 commit comments

Comments
 (0)