Set defaults values and attributes to membership form fields with PHP
you should be able to do this with the buildForm hook that is described here: https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/.
Keep in mind that the custom fields are actually posted on a different form, so I usually first dump the form names to the log with Civi::log()-&gt;debug so I can check what the name I need is.