wpmudev-sls
5/2/2018 - 11:13 AM

Prosite Redirect to Blog URL after checkout

Prosite Redirect to Blog URL after checkout

<?php

/**
* Plugin Name: Prosite Redirect to Blog URL after checkout
* Plugin URI: https://premium.wpmudev.org/
* Description: Prosite Redirect to Blog URL after checkout
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function prosite_custom_redirect_handle( $content ) {

	$session_data                          = array();
	$session_data['new_blog_details']      = ProSites_Helper_Session::session( 'new_blog_details' );
	$session_data['upgraded_blog_details'] = ProSites_Helper_Session::session( 'upgraded_blog_details' );

	if (
		( isset( $session_data['new_blog_details'] ) && isset( $session_data['new_blog_details']['payment_success'] ) && true === $session_data['new_blog_details']['payment_success'] && true === $session_data['new_blog_details']['site_activated'] ) || 
		( isset( $session_data['upgraded_blog_details'] ) && isset( $session_data['upgraded_blog_details']['payment_success'] ) && true === $session_data['upgraded_blog_details']['payment_success'] && true === $session_data['upgraded_blog_details']['site_activated'] )
	) {
		$current = isset( $session_data['new_blog_details'] ) ? $session_data['new_blog_details'] : $session_data['upgraded_blog_details'];
		if ( isset($current['blog_id']) ) {
			$url = get_admin_url( $current['blog_id'] );
			?>
			<script>
				window.location = "<?php echo $url; ?>";
			</script>
			<?php
		}
	}

	return $content;
}

add_filter( 'prosites_render_checkout_page', 'prosite_custom_redirect_handle', 10, 1 );