Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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