• I am using woocommerce and, in the kadence theme settings, I have checked the option to show avatars on the woo account dashboard.

    Currently the avatar links to gravatar, but I need it it either link to nothing (not ideal) or a custom profile settings page (domain.com/profile – I’m using UsersWP).

    Is this possible? I tried copying the file to a corresponding folder in my child theme but that doesn’t seem to work.

    Some info:
    I’m using a child theme called kadence-child
    the gravatar link is in the file /inc/components/woocommerce/component.php

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @8bit7,

    You mentioned you’ve checked the option to show avatars on the Woo account dashboard. Are you referring to the avatar on the My Account page that uses the [woocommerce_my_account] shortcode?

    If so, the component uses the get_avatar() function. You can edit the avatar HTML using the get_avatar filter. The linked filter documentation provides an example to help you change the avatar to something else.

    Thread Starter 8bit7

    (@8bit7)

    Are you referring to the avatar on the My Account page that uses the?[woocommerce_my_account]?shortcode?

    Yes, I am

    If so, the component uses the?get_avatar()?function. You can edit the avatar HTML using the?get_avatar?filter. The linked filter documentation provides an example to help you change the avatar to something else.

    So I’ve been frustrated with this for a couple of days but I still can’t get it to work. Mind showing me an example code for functions.php that could change the link?

    Here’s the relevant code:
    /wp-content/themes/kadence/inc/components/woocommerce/component.php

    /**
    	 * Avatar for myaccount page.
    	 */
    	public function myaccount_nav_avatar() {
    		$current_user = wp_get_current_user();
    		if ( kadence()->option( 'woo_account_navigation_avatar' ) && 0 !== $current_user->ID ) {
    			?>
    			<div class="kadence-account-avatar">
    				<div class="kadence-customer-image">
    				<a class="kt-link-to-gravatar"  target="_blank" rel="no" title="<?php echo esc_attr__( 'Update Profile Photo', 'kadence' ); ?>">
    					<?php echo get_avatar( $current_user->ID, 60 ); ?>
    				</a>
    				</div>
    				<div class="kadence-customer-name">
    					<?php echo esc_html( $current_user->display_name ); ?>
    				</div> 
    			</div>
    			<?php
    		}
    	}

    Hello @8bit7,

    Your snippet should look like the following:

    add_filter( 'get_avatar' , 'my_custom_avatar' , 1 , 5 );
    function my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
         $avatar = 'YOUR_NEW_IMAGE_URL';
         $avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
    
         return $avatar;
    }

    The snippet adds a function to the get_avatar filter. The function returns HTML for the avatar. In this particular case, the code updates the URL and then becomes HTML for an image. You should update the HTML to fit your needs.

    Thread Starter 8bit7

    (@8bit7)

    My apologies if I didn’t explain myself clearly. I’m afraid I haven’t explained myself well, but thank you for that code! Unfortunately that’s not what I was aiming to do.

    I’m trying to change the link to gravatar in the line below

    <a class="kt-link-to-gravatar"  target...
    				

    to something like this…

    <a class="kt-link-to-gravatar"  target...

    I have UserWP that provides a neat profile area for the user and I want to link the avatar kadence displays on the woocommerce account dashboard to that page. I’ve already managed to change and sync up the actual avatar images using get_avatar thankfully, but changing the surrounding link from gravatar.com to mysite.com/profile without editing the core theme file has proved beyond me.

    I do have a kadence-child theme if there is some way to copy over the file, edit it, and make it use my custom file instead? I’ve experimented with this but found no solution. I was hoping it would be as simple as copying the files and adding a snippet to functions.php.

    Hello @8bit7,

    Thanks for clarifying your needs. Instead of the code I provided earlier, try the following snippet. It will add JS to change the link to the link you mentioned. You can update it as necessary. Please let us know if this works for you.

    add_action('wp_footer', function() {
        ?>
        <script>
            jQuery(document).ready(function($) {
                $('.kt-link-to-gravatar').attr('href', 'https://MYURL.com/profile');
            });
        </script>
        <?php
    });
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove link to gravatar in woocommerce account dashboard?’ is closed to new replies.