Preview:
/**
 * Implements hook_views_pre_view().
 */
function enmon_core_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
  if ($view->id() === 'special_offers') {
    $format_values = \Drupal::entityTypeManager()
      ->getStorage('commerce_product_attribute_value')
      ->getQuery()
      ->condition('attribute', 'master_format')
      ->execute();
    $color_values = \Drupal::entityTypeManager()
      ->getStorage('commerce_product_attribute_value')
      ->getQuery()
      ->condition('attribute', 'master_color')
      ->execute();
    $filters = $view->display_handler->getOption('filters');
    if (array_key_exists('attribute_master_format_target_id_1', $filters)) {
      foreach ($format_values as $format_key => $format_value) {
        $filters['attribute_master_format_target_id_1']['value'][$format_key] = $format_value;
      }
    }
    if (array_key_exists('attribute_master_color_target_id_1', $filters)) {
      foreach ($color_values as $color_key => $color_value) {
        $filters['attribute_master_color_target_id_1']['value'][$color_key] = $color_value;
      }
    }
    $view->display_handler->overrideOption('filters', $filters);
  }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter