Redirecting to Checkout when Adding an Item to the Cart

If you want users to be immediately redirected to the checkout page after clicking on the “Purchase” button, you can place the code below into your functions.php or any custom plugin.

 function edd_redirect_to_cart_on_add( $data ) {
	global $edd_options;

	$redirect_url = get_permalink( $edd_options['purchase_page'] );
	if ( edd_get_current_page_url() != $redirect_url ) {
		wp_redirect( $redirect_url, 303 ); 
add_action( 'edd_add_to_cart', 'edd_redirect_to_cart_on_add', 999 );

Note, this only applies to sites that do not have ajax enabled in the Misc settings.

Second note: this is now an option provided by EDD core in Downloads > Settings > Misc.


  1. michalw

    This should use a 303 redirect:

    wp_redirect( $redirect_url, 303 );

    307 will cause Firefox to show a prompt window with following message:

    “This web page is being redirected to a new location. Would you like to resend the form data you have typed to the new location?”


  2. Note: if writing a custom plugin you need to ensure that your call to add_action() is performed before the ‘init’ action.

    edd invokes this action during its init processing, whenever it sees the edd_action keyword in the $GET or $POST.

    The $data that’s passed is either the $POST or the $GET array

    It’s not necessary to return( $data );

    • You’re right, returning the data is not needed, but there is no need to place it in an “init” action. If you look here, you’ll see how the actions are processed (already connected to init).

  3. Edo Melters

    Can somebody help me with this code. I have tried everything but can’t get it to work! I made a custom plugin with the code above but it doesn’t function. I’m not a php expert so getting desperate on this…


Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match