Move WooCommerce Cart Toggle Into the Menu Items

Move WooCommerce Cart Toggle Into the Menu Items

By default, the WooCommerce cart icon is separated from the main menu like this:

If you prefer move the icon as part of the menu items like this:

Then try the following PHP snippet:

add_filter( 'wp_nav_menu_items', function( $items, $args ) {
if ( 'primary' === $args->theme_location ) {
$has_items = false;

if ( ! WC()->cart->is_empty() ) {
$has_items = 'has-items';
}

return sprintf(
'%1$s

',
$items,
generatepress_wc_cart_link(),
is_cart() ? 'current-menu-item' : '',
$has_items
);
}

return $items;
}, 10, 2 );

發表回覆

您的郵箱地址不會被公開。 必填項已用 * 標註