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
            <li class="wc-menu-item menu-item-align-right %3$s %4$s">
                %2$s
            </li>',
            $items,
            generatepress_wc_cart_link(),
            is_cart() ? 'current-menu-item' : '',
            $has_items
        );
    }

    return $items;
}, 10, 2 );