Last active
November 23, 2015 00:51
-
-
Save JudeRosario/3661c2b54be789996c5e to your computer and use it in GitHub Desktop.
myCred App+ Integration
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
// Once the appointment is confirmed, then process the myCreds. | |
add_filter('app_post_confirmation_status', 'confirm_manual_payments',10,5); | |
function confirm_manual_payments($status, $price, $service, $worker, $user_id) { | |
if("pending" === $status || "confirmed" === $status) : | |
global $wp, $current_user; | |
$mycred = mycred(); | |
$current_user = wp_get_current_user(); | |
$balance = round($mycred->get_users_balance( $current_user->ID )); | |
if ( $balance > 0 ) { | |
$mycred->add_creds('appointment', $current_user->ID, -1, '1 %plural% deduction for Appointment Booking'); | |
} | |
// If he somehow hacked around the front end and got through, then put his appointment as pending and get admin to take a look | |
else{ | |
$status = "pending" ; | |
} | |
endif ; | |
return $status; | |
} |
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
add_filter ('app_pre_confirmation_reply','myCred_check') ; | |
// Check if the user has balance, if he has go ahead and do nothing. | |
function myCred_check($ret) { | |
$script = "" ; | |
if ( function_exists( 'mycred' ) ){ | |
global $wp, $current_user; | |
$mycred = mycred(); | |
$current_user = wp_get_current_user(); | |
$balance = round($mycred->get_users_balance( $current_user->ID )); | |
// If no balance then throw alert and hide the confirm button | |
if ( $balance <= 0 ) { | |
$script = <<< myCredCode | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
alert("We cannot confirm this lesson as you have no credits remaining. Please buy additional credits before scheduling a lesson"); | |
jQuery( ".appointments-confirmation-button" ).hide() ; | |
}) | |
</script> | |
myCredCode; | |
} | |
} | |
$ret['service'] .=$script ; | |
return $ret ; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey
its not working right on my site maybe u can give me a Hint.
What i need for this code and where i should put it in