我已经在标题菜单中添加了woocommerce购物车图标,但是我希望它在添加项目时(通过ajax)得到更新。
这是我的代码:
function am_append_cart_icon( $items, $args){
$cart_item_count = WC()->cart->get_cart_contents_count();
$cart_count_span = '';
if ( $cart_item_count ){
$cart_count_span = ''.$cart_item_count.'';
}
$cart_link = ''.$cart_count_span.''; // Add the cart link to the end of the menu.
$items = $items . $cart_link;
return $items;
}
add_filter( 'wp_nav_menu_main-menu_items', 'am_append_cart_icon', 10, 2 );