Created
July 23, 2014 00:21
-
-
Save pippinsplugins/ebcf859c0443b161e40c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/* | |
* Plugin Name: EDD Redirect to Next Product on Add to Cart | |
* Description: Automatically redirects the customer to the next product after they have added an item to the cart | |
* Author: Pippin Williamson | |
* Version: 0.1 | |
*/ | |
function pw_edd_redirect_to_next_scripts( $download_id = 0 ) { | |
global $post; | |
$post = get_post( $download_id ); | |
setup_postdata( $post ); | |
$next = get_adjacent_post(); | |
wp_reset_postdata(); | |
if( ! $next ) { | |
return false; // No additional products | |
} | |
?> | |
<script> | |
jQuery(document).ready(function($) { | |
$('body').on('edd_cart_item_added', function( response ) { | |
window.location = "<?php echo get_permalink( $next->ID ); ?>"; | |
}); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'edd_after_download_content', 'pw_edd_redirect_to_next_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment