need products hidden from group while show to guests
-
Hi! I am struggling to find a solution here:
I got 2 groups, retail and wholesale. I need the retail products to be hidden from wholesale BUT to show for normal guests (visitors without registration).
I have tried to use and modify the 2 codes below but no success. Any help will be greatly appreciated. THX
THIS CODE:
add_filter(‘woocommerce_is_purchasable’, ‘your_custom_function’, 10, 2);
function your_custom_function( $purchaseable, $product ) {
$purchaseable = true;
$is_a_member = false;
require_once( ABSPATH . ‘wp-includes/pluggable.php’ );
if ( $group = Groups_Group::read_by_name( ‘Registered’ ) ) {
$is_a_member = Groups_User_Group::read( get_current_user_id() , $group->group_id );
}
if ( $is_a_member ) {
$purchaseable = false;
}return $purchaseable;
}AND THIS CODE:
<?php
$is_a_member = false;
require_once( ABSPATH . ‘wp-includes/pluggable.php’ );
if ( $group = Groups_Group::read_by_name( ‘Groupname’ ) ) {
$is_a_member = Groups_User_Group::read( get_current_user_id() , $group->group_id );
// Do Stuff Here like maybe php html or jazz hands
}
if ( $is_a_member ) {
// do what needs to be done for the member, for example …
echo ‘Foo!’;
}
?>
- The topic ‘need products hidden from group while show to guests’ is closed to new replies.