Last active
October 2, 2016 11:30
-
-
Save webhasan/551928f68274612e6fef594d3351f382 to your computer and use it in GitHub Desktop.
Woocommerce Mini Cart
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
<?php | |
/** | |
* Wordpress Get The Widget | |
*/ | |
if( !function_exists('get_the_widget') ){ | |
function get_the_widget( $widget, $instance = '', $args = '' ){ | |
ob_start(); | |
the_widget($widget, $instance, $args); | |
return ob_get_clean(); | |
} | |
} | |
/** | |
* Woocommerce Mini Card in widget | |
*/ | |
add_filter( 'wp_nav_menu_items', 'custom_item', 10, 2 ); | |
function custom_item ( $items, $args ) { | |
$count = WC()->cart->cart_contents_count; | |
if(class_exists( 'WooCommerce' )) { | |
$items .= '<li id="mini-card"> | |
<a href="#"><i class="fa fa-shopping-cart"></i>Shop</a><div class="mini-card-product">'.get_the_widget('WC_Widget_Cart').'</div></li>'; | |
} | |
return $items; | |
} | |
/** | |
* Update Mini Cart By Ajax | |
*/ | |
add_filter( 'wp_nav_menu_items', 'custom_item', 10, 2 ); | |
function custom_item ( $items, $args ) { | |
$count = WC()->cart->cart_contents_count; | |
if(class_exists( 'WooCommerce' )) { | |
$items .= '<li id="mini-card"> | |
<a href="#"><i class="fa fa-shopping-cart"></i>Shop</a><div class="mini-card-product">'.get_the_widget('WC_Widget_Cart').'</div></li>'; | |
} | |
return $items; | |
} | |
function mode_theme_update_mini_cart() { | |
echo wc_get_template( 'cart/mini-cart.php' ); | |
die(); | |
} | |
?> | |
<script> | |
var data = { | |
'action': 'mode_theme_update_mini_cart' | |
}; | |
$.post( | |
woocommerce_params.ajax_url, | |
data, | |
function(response){ | |
$('#mode-mini-cart').html(response); | |
} | |
); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment