I am using WooCommerce Memberships by SkyVerge for a membership plan, the issue is, when users buy a membership plz their avatar image should be changed to my custom image URL and when their membership gets expires their avatar will get back to normal
ref:https://woocommerce.com/document/woocommerce-memberships-function-reference/
add_filter('woocommerce-memberships', 'wpb_new_gravatar', 1);
$memberships = wc_memberships_get_user_active_memberships($user_id);
if ($user === $memberships) {
function wpb_new_gravatar($avatar_defaults) {
$myavatar = 'https://buysnd.com/wp-content/uploads/2022/11/Circle_Design_Membership_Level_GOLD.webp';
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}
}
CodePudding user response:
You may need to check doc for howto use hooks, for this specific case, you can use the hook pre_get_avatar
add_filter('pre_get_avatar', 'custom_gravatar', 10, 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://buysnd.com/wp-content/uploads/2022/11/Circle_Design_Membership_Level_GOLD.webp'/>";
}
return $avatar;
}