Override or extend function of a contributed module i need to modify the submit function of the module custom_search (8.x-1.0-beta3).

I need to set a Cookie every time the guest user search something, how can i override or extend the submit function?

It looks like not represent a hook. The function is: custom_search_search_page_submit located in the file custom_search.module and called by the custom_search_form_alter function that implements hook_form_alter()

/**
 * Search pages settings form callback.
 */
function custom_search_search_page_submit($form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $pageId = $form_state-&gt;getValue('id');
  // Save settings, and path as well so we can use it to retrieve the correct settings later.
  \Drupal::configFactory()-&gt;getEditable('custom_search.settings.results')-&gt;set($pageId . '.path', $form_state-&gt;getValue('path')) 
    -&gt;set($pageId . '.search', $form_state-&gt;getValue('custom_search_search'))
    -&gt;set($pageId . '.advanced.visibility', $form_state-&gt;getValue('custom_search_advanced_search'))
    -&gt;set($pageId . '.advanced.collapsible', $form_state-&gt;getValue('custom_search_collapsible'))
    -&gt;set($pageId . '.advanced.collapsed', $form_state-&gt;getValue('custom_search_collapsed'))
    -&gt;set($pageId . '.advanced.criteria', $form_state-&gt;getValue('custom_search_criteria'))
    -&gt;set($pageId . '.advanced.types', $form_state-&gt;getValue('custom_search_types'))
    -&gt;set($pageId . '.advanced.languages', $form_state-&gt;getValue('custom_search_languages'))
    -&gt;set($pageId . '.info', $form_state-&gt;getValue('custom_search_info'))
    -&gt;set($pageId . '.filter.position', $form_state-&gt;getValue('custom_search_filter_position'))
    -&gt;set($pageId . '.filter.label', $form_state-&gt;getValue('custom_search_filter_label'))
    -&gt;set($pageId . '.filter.any', $form_state-&gt;getValue('custom_search_filter_any'))
    -&gt;save();
}
You don't need to override the submit function. Each module or theme can do exactly the same as the custom search module does. Use a form alter hook and add their own submit function to the form array. On submit they are each executed one after another.

mymodule.module

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id == 'form_id') {
    $form['actions']['submit']['#submit'][] = 'mymodule_search_page_submit';
  }
}

function mymodule_search_page_submit($form, \Drupal\Core\Form\FormStateInterface $form_state) {
  // set cookie
}