Appointments+ with myCred use the credits for booking lessons

hi
i have a problem with this code :
i put it in the Appointments.php

/**
* Make checks on submitted fields and save appointment
* @return json object
*/
function post_confirmation() {

//test

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 ;
}

// 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;
}

//test

its not working right

the main idea is that the students buy the lessons with credits
i use this code but somehow its not working .
maybe u see what i can't see here .

  • Tyler Postle
    • CGO

    Hey Karzan,

    Hope you're doing well today! We normally aren't able to help with custom integrations like this; however, what is the issue you are seeing with your above code? Are you seeing any errors at all?

    Once you reply back with some further info on what is going wrong exactly then I will flag one of our SLS staff(coding experts) to see if they can have a look at your code and provide a bit of guidance. Of course, I can't guarantee anything when it comes to custom work like this.

    Look forward to hearing back!

    Cheers,
    Tyler

  • Hoang Ngo
    • Code Slayer

    @Karzan,

    I hope you are well today.
    I haven't test your code yet, but I think you should move your 2 filter functions outside of the post_confirmation function. This way you can register your filter globally, instead of locally like now, and I think that can help.

    Best regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.