Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created July 23, 2014 00:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pippinsplugins/ebcf859c0443b161e40c to your computer and use it in GitHub Desktop.
Save pippinsplugins/ebcf859c0443b161e40c to your computer and use it in GitHub Desktop.
<?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