In functions.php
<form id="video_bekeken" action="">
<input type="hidden" name="inschr" value="<?php echo get_the_ID(); ?>">
<input type="submit" class="btn btn-primary" value="Naar stap 2">
</form>
<script type="text/javascript">
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"
var form = "#video_bekeken";
jQuery(form).submit(function(event) {
event.preventDefault();
jQuery.ajax({
url: ajaxurl + "?action=video_bekeken",
type: 'post',
data: $(form).serialize(),
success: function(data) {
console.log("SUCCESS!");
window.location.replace("https://www.iurislegal.nl/mijn-account/ondemand/#inschrijving<?php echo get_the_ID();?>");
},
error: function(data) {
console.log("FAILURE");
}
});
});
</script>
In het thema
function video_bekeken_action_callback() {
$post_id = $_POST['inschr'];
if (isset($post_id)):
//unshedule event reminder video bekijken
// schedule reminder codewoorden
$nu = date('Y-m-d H:i:s');
$unix_nu = strtotime($nu);
$twaald_uur_later = strtotime('+14 hours', $unix_nu);
$zes_uur_later = strtotime('+8 hours', $unix_nu);
update_field( 'video_bekeken', 1, $post_id );
update_field( 'stap_een_afgerond', 1, $post_id );
update_field( 'datum_reminder_codewoorden', $zes_uur_later, $post_id );
update_field( 'datum_verlopen_codewoorden', $twaald_uur_later, $post_id );
//wp_schedule_single_event( $unix_time_info_datum , 'mail_cursus_info_cron', array( $post_id, $cursusnaam ) );
endif;
}
add_action( 'wp_ajax_nopriv_video_bekeken', 'video_bekeken_action_callback' );
add_action( 'wp_ajax_video_bekeken', 'video_bekeken_action_callback' );
#acf #AJAX #functions #jQuery