Created
June 27, 2017 10:21
-
-
Save andrewlimaza/ee6768a8a738847a4084078ed58ec73e to your computer and use it in GitHub Desktop.
Example for custom 'depends' functionality for PMPro Register Helper add-on
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 | |
/** | |
* 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