For a quick fix, change $memType['auto_renew'] to ($memType['auto_renew'] ?? 0) for the first one, and
change $membershiptTypeValue['auto_renew'] to !empty($membershiptTypeValue['auto_renew']) for the second one.
There are a few things you can try here:
Go to CiviCRM's Administer menu >> System Settings >> CMS Database Integration. Compare the array there against the one listed in settings.php. This array (in settings.php) must be updated when you add new custom field groups to CiviCRM (since they add new tables). This is most likely your issue.
There is an extension that does that: https://github.com/Project60/org.project60.membership
It can do much more than only connecting memberships and contributions via the UI so make sure that it's not an overkill for your purposes ;)
Unfortunately, there is no coherent documentation so for some features you may want to contact the maintainer (Björn from ...
Issue was resolved by having Grace status End Date Adjustment set to 24 months after the membership end date. The Expired status was left with a Start Date of 2 years after the membership end date. For some reason if the two timings were set to be the same (i.e. 2 years or 24 months) the Expired status never kicked in.
It would be nice if it worked as you have set it up but multiple terms are not compatible with auto-renew.
The documentation for multiple membership terms includes this caveat at the end:
However you need to be aware that your members will not be able to auto-renew if you use this type of multi-term configuration.
It sounds like there's a misconfiguration of your Membership Status Rules.
Please review them at Administer menu >> CiviMember >> Membership Status Rules. Pay special attention to the Grace and Expired rules, especially to the Start Date Adjustment and End Date Adjustment.
If you're not sure how to interpret what you're seeing, feel free to edit ...