hi there m using WooCommerce Memberships by SkyVerge for a membership plan, m trying to make conditional avatars for users and members, when the user is a member their avatar is different and when he is not a member then different, I have two sample codes, can anyone make them conditional
// Custom Default Gravatar Only For Members
add_filter( 'pre_get_avatar', 'custom_gravatar', 1, 3 );
function custom_gravatar( $avatar, $id_or_email, $args ) {
$uid = get_current_user_id();
if ( $uid && wc_memberships_get_user_active_memberships( $uid ) ) {
$avatar = "<img src='https://staranddaisy.in/wp-content/uploads/2022/11/Circle_Design_Membership_Level_GOLD.webp'/>";
}
return $avatar;
}
// Default Gravatar For Non-Members or Users
add_filter( 'avatar_defaults', 'wpb_new_gravatar' );
function wpb_new_gravatar( $avatar_defaults ) {
$myavatar = 'http://staranddaisy.in/wp-content/uploads/2022/11/smily_icon_avatar-1.png';
$avatar_defaults[ $myavatar ] = 'Default Gravatar';
return $avatar_defaults;
}
2
Answers
I cant test it at full bcs of the membership plugin but this should work