Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Last active April 4, 2023 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thierrypigot/7b2ce0ee05ee803fa649f69971b4b56f to your computer and use it in GitHub Desktop.
Save thierrypigot/7b2ce0ee05ee803fa649f69971b4b56f to your computer and use it in GitHub Desktop.
Custom CF7 select field values
<?php
/**
* Use this CF7 field [select dates_cyril], field name is "dates_cyril"
**/
add_filter( 'wpcf7_form_tag', 'waw_dynamic_select_field_values', 10, 2);
function waw_dynamic_select_field_values ( $scanned_tag, $replace ) {
if ( $scanned_tag['name'] != 'dates_cyril' ) {
return $scanned_tag;
}
$scanned_tag['raw_values'] = array(
'' => __('&mdash; Choisir une date &mdash;'),
'Mardi 18 avril - 18h' => 'Mardi 18 avril - 18h',
'Mardi 2 mai - 18h' => 'Mardi 2 mai - 18h',
'Mardi 16 mai - 18h' => 'Mardi 16 mai - 18h',
);
$pipes = new WPCF7_Pipes( $scanned_tag['raw_values'] );
$scanned_tag['values'] = $pipes->collect_befores();
$scanned_tag['labels'] = $pipes->collect_afters();
$scanned_tag['pipes'] = $pipes;
return $scanned_tag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment