Last active
August 29, 2015 14:06
-
-
Save bappi-d-great/25174d01b7f5741d4c81 to your computer and use it in GitHub Desktop.
Load service providers via ajax in WPMU Appointments
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 | |
add_action( 'wp_footer', 'ajax_app_auto_load' ); | |
function ajax_app_auto_load() { | |
?> | |
<style> | |
.app_services_button{display: none;} | |
</style> | |
<script type="text/javascript"> | |
jQuery(function($){ | |
$('.app_select_services').prepend('<option selected="selected" value="">Select a service</option>'); | |
$('.app_select_services').change(function() { | |
var val = $(this).val(), | |
ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', | |
data = { | |
'action': 'ajax_app_provider_load_action', | |
'service': val | |
}; | |
if( val != '' ) { | |
$.post(ajaxurl, data, function(response) { | |
$('.app_select_workers').html(response); | |
}); | |
} | |
}); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_ajax_ajax_app_provider_load_action', 'ajax_app_provider_load_action_cb' ); | |
add_action( 'wp_ajax_nopriv_ajax_app_provider_load_action', 'ajax_app_provider_load_action_cb' ); | |
function ajax_app_provider_load_action_cb() { | |
global $appointments; | |
$workers = $appointments->get_workers_by_service( $_POST['service'], 'ID' ); | |
$s = '<option value="0">No preference</option>'; | |
foreach ( $workers as $worker ) { | |
$s .= '<option value="'.$worker->ID.'">'. $appointments->get_worker_name( $worker->ID ) . '</option>'; | |
} | |
echo $s; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment