How can I fix the redirect chain after implementing ssl on wordpress?

If you are doing this in .htaccess then I wouldn’t try to do this in a single redirect. The longest “chain” should be two redirects (1, 2 or even 3 redirects makes no difference for SEO):

  1. Canonicalise the HTTP to HTTPS and www to non-www in the first redirect
  2. Append the trailing slash in the second redirect.

(If, however, you are implementing HSTS then you would need to implement the HTTP to HTTPS redirect (on the same hostname) first. Then canonicalise the subdomain. This potentially makes a maximum of 3 redirects.)

This appears to be what you are seeing in your first example.

It’s possible to append the trailing slash in .htaccess, however, you’ve not shown this code so I’m assuming WordPress is configured to do this?

Currently, it redirects from http://www.example.com/foo via http://example.com/foo to https://example.com/foo and https://example.com/foo/.

However, this doesn’t correlate with the directives you posted, assuming these are at the top of your .htaccess file:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

These directives only redirect to https://, so it’s not clear where your second stage redirect to http://example.com/foo is coming from? Unless maybe you are seeing a cached response?

Presumably, you are already linking to URLs with a trailing slash throughout your application, and you previously implemented a canonical www to non-www redirect, so any requests for http://www.example.com/foo should be a relatively rare occurrence. (?)