Skip to content

Instantly share code, notes, and snippets.

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 andrewlimaza/ee6768a8a738847a4084078ed58ec73e to your computer and use it in GitHub Desktop.
Save andrewlimaza/ee6768a8a738847a4084078ed58ec73e to your computer and use it in GitHub Desktop.
Example for custom 'depends' functionality for PMPro Register Helper add-on
<?php
/**
* This code recipe is an example to manually hide/show fields according to user's selection for Paid Memberships Pro + Register Helper Add-on.
* Please add the following code to your PMPro Customizations plugin -
* This is ideal for smaller solutions for wanting to use 'depends' functionality of more than one field.
* The field 'some_slect' acts as the parent and depending on the selection it will show you either show_this or show_this_field_2 divs.
*/
function simple_js_to_toggle_stuff(){
?>
<script>
jQuery(document).ready(function(){
//Hide all fields that depends on the values.
jQuery('#show_this_div').hide();
jQuery('#show_this_field_2_div').hide();
jQuery('#some_select').change(function(){
var value_of_select = jQuery('#some_select').val();
switch(value_of_select){
case 'option_1':
jQuery('#show_this_div').show();
jQuery('#show_this_field_2_div').hide();
break;
case 'option_2':
jQuery('#show_this_div').hide();
jQuery('#show_this_field_2_div').show();
break;
default:
jQuery('#show_this_div').hide();
jQuery('#show_this_field_2_div').hide();
}
});
});
</script>
<?php
}
add_action( 'wp_footer', 'simple_js_to_toggle_stuff' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment