我在函数中使用此代码。php的主题,以便在购物车菜单项旁边添加购物车信息。
但是,此代码在<li>
我想把这些信息<li>
.
您能帮我更改此代码以便在<li>
?
谢谢
/**
* This function adds the WooCommerce or Easy Digital Downloads cart icons/items to the top_nav menu area as the last item.
*/
add_filter( \'wp_nav_menu_items\', \'my_wp_nav_menu_items\', 10, 2 );
function my_wp_nav_menu_items( $items, $args, $ajax = false ) {
// Top Navigation Area Only
if ( ( isset( $ajax ) && $ajax ) || ( property_exists( $args, \'theme_location\' ) && $args->theme_location === \'primary\' ) ) {
// WooCommerce
if ( class_exists( \'woocommerce\' ) ) {
$css_class = \'menu-item menu-item-type-cart menu-item-type-woocommerce-cart\';
// Is this the cart page?
if ( is_cart() )
$css_class .= \' current-menu-item\';
//$items .= \'<li class="\' . esc_attr( $css_class ) . \'">\';
$items .= \'<a class="cart-contents" href="\' . esc_url( WC()->cart->get_cart_url() ) . \'">\';
// $items .= wp_kses_data( WC()->cart->get_cart_total() ) . \' - <span class="count">\' . wp_kses_data( sprintf( _n( \'%d item\', \'%d items\', WC()->cart->get_cart_contents_count(), \'simple-shop\' ), WC()->cart->get_cart_contents_count() ) ) . \'</span>\';
$items .= \' (<span class="count">\' . wp_kses_data( sprintf( _n( \'%d\', \'%d\', WC()->cart->get_cart_contents_count(), \'simple-shop\' ), WC()->cart->get_cart_contents_count() ) ) . \'</span>)\';
$items .= \'</a>\';
//$items .= \'</li>\';
}
}
return $items;
}
/**
* This function updates the Top Navigation WooCommerce cart link contents when an item is added via AJAX.
*/
add_filter( \'woocommerce_add_to_cart_fragments\', \'my_woocommerce_add_to_cart_fragments\' );
function my_woocommerce_add_to_cart_fragments( $fragments ) {
// Add our fragment
$fragments[\'li.menu-item-type-woocommerce-cart\'] = my_wp_nav_menu_items( \'\', new stdClass(), true );
return $fragments;
}
EDIT (new code)
add_filter( \'wp_setup_nav_menu_item\',\'my_item_setup\' );
function my_item_setup($item) {
if ( class_exists( \'woocommerce\' ) ) {
global $woocommerce;
?>
<!--<pre><?php //var_dump( $woocommerce->cart->get_cart_contents_count() ); ?></pre>-->
<?php
if ( $item->url == esc_url( wc_get_cart_url() ) ) {
//$item->title = \'MY BAG(\'. \'<span class="count">\' . wp_kses_data( sprintf( _n( \'%d\', \'%d\', WC()->cart->get_cart_contents_count(), \'simple-shop\' ), WC()->cart->get_cart_contents_count() ) ) . \'</span>)\';
//$item->title = \'MY BAG(\'. \'<span class="count">\' . wp_kses_data( sprintf( _n( \'%d\', \'%d\', $woocommerce->cart->cart_contents_count(), \'simple-shop\' ), $woocommerce->cart->cart_contents_count() ) ) . \'</span>)\';
$item->title = \'MY BAG(\'. \'<span class="count">\' . $woocommerce->cart->get_cart_contents_count() . \'</span>)\';
//$item->title = sprintf( _n( \'%d\', \'%d\', $woocommerce->cart->cart_contents_count();, \'simple-shop\' ), $woocommerce->cart->cart_contents_count(); );
}
}
return $item;
}