Skip to content

Instantly share code, notes, and snippets.

@jadealombro
Last active April 21, 2022 14:01
Show Gist options
  • Save jadealombro/455210743f81c6e6a7605d2b1e9a81c7 to your computer and use it in GitHub Desktop.
Save jadealombro/455210743f81c6e6a7605d2b1e9a81c7 to your computer and use it in GitHub Desktop.
Disable some checkboxes, radio buttons, and dropdown options in WPForms
<?php
add_action( 'wpforms_wp_footer_end', function () {
?>
<script type="text/javascript">
jQuery(function($){
// This array contains all the options that will be disabled
// 2217 is the form ID
// 1, 2, 3 after #wpforms-2217-field_ are the field IDs
var disable = [
'#wpforms-2217-field_1-container option[value="Second Choice"]', // Disable Second Choice option in a dropdown
'#wpforms-2217-field_2-container input[value="Second Choice"]', // Disable Second Choice option in a checkbox
'#wpforms-2217-field_2-container input[value="Third Choice"]', // Disable Third Choice option in a checkbox
'#wpforms-2217-field_3-container input[value="Third Choice"]' // Disable Second Choice option in a radio button (multiple choice)
];
$.each( disable, function( key, value ) {
$(value).prop('disabled', true);
});
});
</script>
<?php
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment