How can I make the coupon code field in commerce mandatory?
You must do this in a hook_form_FORM_ID_alter().

You wouldn't use hook_form_alter() unless you are checking on a dynamic form ID. In this case it's better to use hook_form_FORM_ID_alter().

The reason for this, is that hook_form_alter() is called on every form render and hook_form_FORM_ID_alter() is only called when that specific form is being rendered.

Add this code to your .module file to make the field required:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MY_MODULE_form_commerce_checkout_form_checkout_alter(&amp;$form, &amp;$form_state, $form_id) {
  if (!empty($form['commerce_coupon']['coupon_code'])) {
    $form['commerce_coupon']['coupon_code']['#required'] = TRUE;
  }
}