Last active
August 26, 2021 19:22
-
-
Save neilgee/2de0785ae6679b6be3a8f2ebf452c245 to your computer and use it in GitHub Desktop.
WooCommerce Cart Icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* # WooCommerce Cart Icon CSS with FontAwesome 5 | |
---------------------------------------------------------------------------------------------------- */ | |
.cart-contents { | |
position: relative; | |
display: flex !important; | |
flex-flow: column nowrap; | |
justify-content: center; | |
} | |
.cart-contents:before { | |
font-family: 'Font Awesome 5 Free'; | |
font-weight: 900; | |
content: "\f290" !important; | |
font-size: 30px; | |
color: #FF1493; | |
} | |
.cart-contents:hover { | |
text-decoration: none; | |
} | |
.cart-contents-count { | |
position: absolute; | |
top: 15px; | |
right: 1px; | |
transform: translateY(-105%) translateX(25%); | |
font-family: Arial, Helvetica, sans-serif; | |
font-weight: normal; | |
font-size: 12px; | |
line-height: 22px; | |
height: 22px; | |
width: 22px; | |
vertical-align: middle; | |
text-align: center; | |
color: #fff; | |
background: #000; | |
border-radius: 50%; | |
padding: 1px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // <~ don't add me in | |
add_filter( 'woocommerce_add_to_cart_fragments', 'woo_cart_but_count' ); | |
/** | |
* Add AJAX Shortcode when cart contents update | |
*/ | |
function woo_cart_but_count( $fragments ) { | |
ob_start(); | |
$cart_count = WC()->cart->cart_contents_count; | |
$cart_url = wc_get_cart_url(); | |
?> | |
<a class="cart-contents menu-item" href="<?php echo $cart_url; ?>" title="<?php _e( 'View your shopping cart' ); ?>"> | |
<?php | |
if ( $cart_count > 0 ) { | |
?> | |
<span class="cart-contents-count"><?php echo $cart_count; ?></span> | |
<?php | |
} | |
?></a> | |
<?php | |
$fragments['a.cart-contents'] = ob_get_clean(); | |
return $fragments; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // <~ don't add me in | |
add_shortcode ('woo_cart_but', 'woo_cart_but' ); | |
/** | |
* Create Shortcode for WooCommerce Cart Menu Item | |
*/ | |
function woo_cart_but() { | |
ob_start(); | |
$cart_count = WC()->cart->cart_contents_count; // Set variable for cart item count | |
$cart_url = wc_get_cart_url(); // Set Cart URL | |
?> | |
<li><a class="menu-item cart-contents" href="<?php echo $cart_url; ?>" title="My Basket"> | |
<?php | |
if ( $cart_count > 0 ) { | |
?> | |
<span class="cart-contents-count"><?php echo $cart_count; ?></span> | |
<?php | |
} | |
?> | |
</a></li> | |
<?php | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment