wp_nav_menu() - Displays a navigation menu - contains wp_nav_menu_{$menu->slug}_items
filter hook.
/**
* Filters the HTML list content for a specific navigation menu.
*
* @since 3.0.0
*
* @see wp_nav_menu()
*
* @param string $items The HTML list content for the menu items.
* @param stdClass $args An object containing wp_nav_menu() arguments.
*/
$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );
So to answer your question, use:
function custom_minicart_in_main_menu( $items, $args ) {
// Get cart url
$link_url = wc_get_cart_url();
// Text
$link_text = sprintf( __( 'Cart (%d) - %s', 'woocommerce' ), WC()->cart->cart_contents_count, WC()->cart->get_total() );
// Link
$minicart_link = '<a class="custom-minicart" href="' . $link_url . '">' . $link_text . '</a>';
return $items . $minicart_link;
}
add_filter( 'wp_nav_menu_header-menu_items', 'custom_minicart_in_main_menu', 10, 2 );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…