Refresh page after payment complete

Put the following snippet in your functions.php in order to automatically refresh the page when payment comes through.

This is useful if you have products where the download links are not active until the order has been paid.


add_action( 'edd_payment_receipt_after_table', 'mcc_refresh_after_payment' );
add_action( 'woocommerce_order_details_after_order_table', 'mcc_refresh_after_payment' );
function mcc_refresh_after_payment()
{
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ )
{
	function mcc_has_paid()
	{
		// When we detect the paid div, reload the page.
		var $paid = $( '.mcc_payment_timer .paid' );
		if ( $paid.length < 1 )
			return false;
		if ( ! $paid.is( ':visible' ) )
			return false;
		return true;
	}

	setTimeout( function()
	{
		// Already paid when starting? Do nothing.
		if ( mcc_has_paid() )
			return;

		$div = $( '.mcc.online_payment_instructions' );
		if ( $div.length < 1 )
			return;
		// Start a timer and wait for payment complete.
		var interval = setInterval( function()
		{
			if ( ! mcc_has_paid() )
				return;
			clearInterval( interval );
			document.location = document.location;
		}, 1000 );
	}, 10000 );
} );
</script>
<?php
}