TwigExtension added to Craft don’t work in emails
All you should need to do is remove this condition check:

if (Craft::$app-&gt;request-&gt;getIsSiteRequest()) {


You are only registering the twig extension for front end (site) requests, but emails can be triggered both on a cart complete front end (site) requests AND a back-end (CP) order status changes.