Last active
April 4, 2023 14:32
-
-
Save thierrypigot/7b2ce0ee05ee803fa649f69971b4b56f to your computer and use it in GitHub Desktop.
Custom CF7 select field values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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( | |
'' => __('— Choisir une date —'), | |
'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