Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redirect to checkout page after appointment made
<?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
You can’t perform that action at this time.