February 23, 2021
to hide prices / add to cart until a user logs? Woocommerce
Author:
jameshwartlopez
Description:
met hide cart
https://gist.github.com/jameshwartlopez/3fe1b860fa77d814fac908bace3da83c
Kind:
PHP, woocommerce
PHP:
add_filter('woocommerce_get_price_html','members_only_price');
function members_only_price($price){
if(is_user_logged_in() ){
return $price;
}
else return 'Login om de prijs te zien!';
}
add_filter('woocommerce_is_purchasable', 'my_woocommerce_is_purchasable', 10, 2);
function my_woocommerce_is_purchasable($is_purchasable, $product) {
$isLoggedIn = is_user_logged_in();
if(true == $isLoggedIn){
//Make product purchasable to logged in user
return true;
}
//Make product not purchasable to unlogged in user
return false;
}
URL:
- https://wordpress.org/support/topic/hide-prices/
- https://gist.github.com/jameshwartlopez/3fe1b860fa77d814fac908bace3da83c