Created
August 18, 2016 08:38
-
-
Save champsupertramp/4002dbc2386b80c7dccbfe6865a0fb17 to your computer and use it in GitHub Desktop.
Ultimate Member - Calculate two profile fields
This file contains hidden or 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 | |
// Profile View | |
add_filter("um_profile_field_filter_hook__myMetaKeyC","um_profile_field_filter_hook__myMetaKeyC"); | |
function um_profile_field_filter_hook__myMetaKeyC( $value, $data ){ | |
$a = um_user("myMetaKeyA"); | |
$b = um_user("myMetaKeyB"); | |
$value = intval( $a ) + intval( $b ); | |
return $value; | |
} | |
// Editing View | |
add_filter("um_edit_myMetaKeyC_field_value","um_edit_myMetaKeyC_field_value"); | |
function um_edit_myMetaKeyC_field_value( $value, $key ){ | |
$a = um_user("myMetaKeyA"); | |
$b = um_user("myMetaKeyB"); | |
$value = intval( $a ) + intval( $b ); | |
return $value; | |
} | |
?> | |
// Here's the jQuery version of calculations in editing view: | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
var $um_field = $("input[data-key='myMetaKeyA'],input[data-key='myMetaKeyB']"); | |
$um_field.keyup(function(){ | |
um_calculate_fields(); | |
}); | |
function um_calculate_fields(){ | |
var a = $("input[data-key='myMetaKeyA']").val(); | |
var b = $("input[data-key='myMetaKeyB']").val() | |
var calc = parseInt( a ) + parseInt( b ); | |
var total = isNaN( calc ) ? 0: calc; | |
$("input[data-key='myMetaKeyC']").val( total ); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment