Created
September 3, 2020 16:08
-
-
Save Jahid07/3c39a528ec75645b681f8bb587600d97 to your computer and use it in GitHub Desktop.
Add woocommerce cart icon in Wordpress menu Divi theme
This file contains hidden or 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
| ------------------------------ ADDITIONAL CSS HERE ------------------------------*/ | |
| /* # WooCommerce Cart Icon CSS with FontAwesome 5 | |
| ---------------------------------------------------------------------------------------------------- */ | |
| .cart-contents{ | |
| position: relative; | |
| } | |
| .cart-contents:before { | |
| font-family:'ETmodules'; | |
| content: "\e013"; | |
| font-size:28px; | |
| font-style:normal; | |
| font-weight:400; | |
| padding-right:5px; | |
| vertical-align: bottom; | |
| } | |
| .cart-contents:hover { | |
| text-decoration: none; | |
| } | |
| #menu-home-menu li span.cart-contents-count { | |
| color: #fff; | |
| background-color: red; | |
| font-weight: bold; | |
| border-radius: 3px; | |
| padding: 4px 4px; | |
| line-height: 1; | |
| font-family: Arial, Helvetica, sans-serif !important; | |
| position: absolute; | |
| top: 12px; | |
| right: 0px; | |
| font-size: 8px; | |
| } | |
This file contains hidden or 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
| add_filter( 'wp_nav_menu_home-menu_items', 'woo_cart_but_icon', 10, 2 ); // Change menu to suit - example uses 'home-menu' | |
| /** | |
| * Add WooCommerce Cart Menu Item Shortcode to particular menu | |
| */ | |
| function woo_cart_but_icon ( $items, $args ) { | |
| if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| $count = WC()->cart->cart_contents_count; | |
| if($count > 0){ | |
| $cuntVal = '<span class="cart-contents-count">'.$count.'</span>'; | |
| }else{ | |
| $cuntVal = '<span class="cart-contents-count">'. 0 .'</span>'; | |
| } | |
| $items .= '<li><a class="cart-contents" href="'.WC()->cart->get_cart_url().'" title="View your shopping cart">'.$cuntVal.'</a></li>'; | |
| return $items; | |
| } | |
| } | |
| /** | |
| * Ensure cart contents update when products are added to the cart via AJAX | |
| */ | |
| function my_header_add_to_cart_fragment( $fragments ) { | |
| ob_start(); | |
| $count = WC()->cart->cart_contents_count; | |
| ?><a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php | |
| ?> | |
| <span class="cart-contents-count"><?php echo esc_html( $count ); ?></span> | |
| <?php | |
| ?></a><?php | |
| $fragments['a.cart-contents'] = ob_get_clean(); | |
| return $fragments; | |
| } | |
| add_filter( 'woocommerce_add_to_cart_fragments', 'my_header_add_to_cart_fragment' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment