Created
July 13, 2017 10:43
-
-
Save panoslyrakis/afadb553ed0ec370ef85d6aa1fcc03a5 to your computer and use it in GitHub Desktop.
Redirect to checkout page after appointment made
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 | |
//Requires App+ and MarketPress | |
add_action( 'wp_footer', function(){ | |
global $post; | |
if( ! $post instanceof WP_Post || strpos( $post->post_content, '[app_' ) === false || ! function_exists('mp_store_page_url') ){ | |
return; | |
} | |
$checkout_page = mp_store_page_url( 'checkout', false ); | |
?> | |
<script type="text/javascript"> | |
(function($){ | |
var WPMUDEV_App_Post_Confirm = { | |
load: function(){ | |
$( document ).ajaxComplete(function( event, xhr, settings ) { | |
var action = WPMUDEV_App_Post_Confirm.get_action( 'action', settings.data ); | |
var response = JSON.parse(xhr.responseText); | |
if( action == 'post_confirmation' && typeof response.error === 'undefined' ){ | |
document.location="<?php echo $checkout_page; ?>"; | |
} | |
}); | |
}, | |
get_action: function(name, url){ | |
if (!url){ | |
return ''; | |
} | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
//var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | |
var regex = new RegExp(name + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} | |
}; | |
$( document ).ready(function(){ | |
WPMUDEV_App_Post_Confirm.load(); | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
}, 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment