Archived topic
change cart icon and remove double carts displaying
5 replies · Started by Jeroen on April 19, 2021
Hi
I run into two issues, I want to replace the svg of the cart icon. I found some filter code on the forums, (https://generatepress.com/forums/search/replace+cart+icon/) I added it to my functions.php but the icon does not change...?
Also, I now have two icons in my nav and need only one (the one with the # of items in cart only). I will add login data below since it needs be behind a login. Could you pls take a look?
Jeroen
ps i want to use
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 95 89.4"><path d="M92.9 18.4c-1.8-2.3-4.6-3.7-7.5-3.7H24.5l-1.9-7.4C21.5 3 17.7 0 13.3 0H3.1C1.4 0 0 1.4 0 3.1s1.4 3.1 3.1 3.1h10.2c1.5 0 2.8 1 3.2 2.5l12.2 48.6c1.1 4.3 4.9 7.3 9.3 7.3h39.9c4.4 0 8.3-3 9.3-7.3l7.5-30.8c.7-2.8.1-5.8-1.8-8.1zm-4.3 6.7l-7.5 30.8c-.4 1.5-1.7 2.5-3.2 2.5H38c-1.5 0-2.8-1-3.2-2.5L26.1 21h59.3c1 0 2 .5 2.6 1.3.6.8.9 1.8.6 2.8zM40.1 68.6c-5.7 0-10.4 4.7-10.4 10.4s4.7 10.4 10.4 10.4S50.5 84.7 50.5 79s-4.7-10.4-10.4-10.4zm0 14.5c-2.3 0-4.1-1.8-4.1-4.1s1.8-4.1 4.1-4.1 4.1 1.8 4.1 4.1c0 2.2-1.9 4.1-4.1 4.1zM74.5 68.6c-5.7 0-10.4 4.7-10.4 10.4s4.7 10.4 10.4 10.4S84.9 84.7 84.9 79c-.1-5.7-4.7-10.4-10.4-10.4zm0 14.5c-2.3 0-4.1-1.8-4.1-4.1s1.8-4.1 4.1-4.1 4.1 1.8 4.1 4.1c0 2.2-1.9 4.1-4.1 4.1z"/></svg>
Hi there,
Try this filter:
add_filter( 'generate_svg_icon', function( $output, $icon ) {
if ( 'shopping-cart' === $icon ) {
$svg = '<svg viewBox="0 0 95 89.4" aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M92.9 18.4c-1.8-2.3-4.6-3.7-7.5-3.7H24.5l-1.9-7.4C21.5 3 17.7 0 13.3 0H3.1C1.4 0 0 1.4 0 3.1s1.4 3.1 3.1 3.1h10.2c1.5 0 2.8 1 3.2 2.5l12.2 48.6c1.1 4.3 4.9 7.3 9.3 7.3h39.9c4.4 0 8.3-3 9.3-7.3l7.5-30.8c.7-2.8.1-5.8-1.8-8.1zm-4.3 6.7l-7.5 30.8c-.4 1.5-1.7 2.5-3.2 2.5H38c-1.5 0-2.8-1-3.2-2.5L26.1 21h59.3c1 0 2 .5 2.6 1.3.6.8.9 1.8.6 2.8zM40.1 68.6c-5.7 0-10.4 4.7-10.4 10.4s4.7 10.4 10.4 10.4S50.5 84.7 50.5 79s-4.7-10.4-10.4-10.4zm0 14.5c-2.3 0-4.1-1.8-4.1-4.1s1.8-4.1 4.1-4.1 4.1 1.8 4.1 4.1c0 2.2-1.9 4.1-4.1 4.1zM74.5 68.6c-5.7 0-10.4 4.7-10.4 10.4s4.7 10.4 10.4 10.4S84.9 84.7 84.9 79c-.1-5.7-4.7-10.4-10.4-10.4zm0 14.5c-2.3 0-4.1-1.8-4.1-4.1s1.8-4.1 4.1-4.1 4.1 1.8 4.1 4.1c0 2.2-1.9 4.1-4.1 4.1z"/></svg>';
return sprintf(
'<span class="gp-icon %1$s">
%2$s
</span>',
$icon,
$svg
);
}
return $output;
}, 15, 2 );
Hi Elvin,
Thank you, I did, (it's the same code I found earlier), but nothing changes. I put it in functions.php in the generatepress_child theme, right?
Thank you, I did, (it’s the same code I found earlier), but nothing changes. I put it in functions.php in the generatepress_child theme, right?
I've tested the code prior to posting it and it works. See my sandbox site - Sandbox site
Yes, you can use a child theme's functions.php or Code Snippets plugin.
Code snippets plugin is easier to use.
Do you have multiple instance of the same filter? That can cause issues. Let us know.
I found it, it should have been 'bag' instead of 'cart'
if ( 'shopping-bag' === $icon )
Ah yes if you're using bag, basket or cart it'll have to match.
Glad you got it sorted. Thank you for letting us know. :)