Easy-digital-downloads: Redirect to checkout setting conflicts with multiple checkout pages

Created on 19 Jun 2018  路  10Comments  路  Source: easydigitaldownloads/easy-digital-downloads

_EDD version 2.9.3_

The new multiple checkout page feature works well, but has an interesting edge case:

If using ?add_to_cart in a URL going to an alternate checkout page, the user is redirected to the main checkout page if the Redirect to checkout setting is set to true.

For instance:

  1. I navigate to https://mylocalsite.test/alternate-checkout?edd_action=add_to_cart&download_id=481
  2. I expect to end up on https://mylocalsite.test/alternate-checkout with the download with ID 481 in my cart.
  3. Instead, I end up on https://mylocalsite.test/checkout with download 481 in my cart.

If I uncheck Redirect to checkout on the Misc. tab of EDD settings, then number 2 above works as expected/desired.

I'm not sure what a good fix here is... it would be _nice_ if that setting could be turned on, but direct navigation to an alternate checkout page were allowed (and thus bypassed the redirect).

For this to happen, edd_is_checkout() would need to return true for any page with the [download_checkout] shortcode present. This is _probably_ a good idea anyway, though perhaps there are edge cases there to consider as well.

In edd_is_checkou(), $wp_query->queried_object appears to not be set in this case; if it were, I believe that function would return true, because it does check for the presence of the [download_checkout] shortcode... _if_ the queried_object property is set (and if is_singular() returns true).

component-checkout type-bug

Most helpful comment

So I've got some slightly different results, but I actually think what I'm experiencing is more desirable behavior:

Custom add to cart link, linking to the alternate cart, with redirect to checkout checked: Results in The alternate checkout with the item in the cart.

Custom add to cart link, linking to alternate cart, with redirect to checkout unchecked: Also results in being at the alternate checkout with the item in the cart.

So the item is being added to the cart for me now in all cases.

All 10 comments

EDD 2.9.3

Using a URL like: https://mysite.com/checkout-alt?edd_action=add_to_cart&download_id=1813&edd_options[price_id]=3

With Immediately redirect to checkout after adding an item to the cart? checked: Redirects to default checkout page without adding item to cart.

With Immediately redirect to checkout after adding an item to the cart? unchecked: Goes to checkout-alt page but does not add item to cart.

Just testing and wanted to note that edd_is_checkout does return true on alternate checkout pages. I'm not having an issue with it detecting them, or else none of our JS would load. The issue likely lies just in the load order that adding to cart runs.

Still investigating though

In my testing:

Custom add to cart link, linking to the alternate cart, with redirect to checkout _checked_: Results in The default checkout with the item in the cart.

Custom add to cart link, linking to alternate cart, with redirect to checkout _unchecked_: Results in being at the alternate checkout _with_ the item in the cart.

Seems like i'm replicating the results that @tnorthcutt is having. @sambrodie I'm not sure how you're getting an empty cart at the alternate checkout. I'll have to keep investigating that part. Anything particular about the hosting environment? Object caching place etc?

Ok I pushed up some changes, going to wait on a code review in order to determine if my 'solution' works long term, but it should sure this up a bit if it's considered viable.

@cklosowski I've replicated the original issue on master. Like you, I can't replicate what @sambrodie experienced.

issue/6668 is working for me. I'm not totally sure what things you're concerned with in regards to your PR. Is there a specific concern about your approach?

@SDavisMedia in general it's just a brand new concept of actions that should not run on init but wait until template_redirect.

What was happening is that the edd_add_to_cart was running, and because it was so early (on init), the proper checkout URI could not be determined because the $wp_query is unpopulated on init. My main concern is if we think this is an "ok" construct to add (the concept of actions we _know_ should wait until later to be run) or if we should rethink from a different perspective.

Clever approach, I like it.

At the moment I cannot think of any downsides to it beyond a very minute increase in processing time for add to cart actions.

@cklosowski Got it. That was my understanding. I thought we did something similar with actions after processing payments. Seems like a good approach to me if you all don't have issues with it.

@SDavisMedia @pippinsplugins I'm going to merge this into master and then get master running on our own EDD site for a bit.

@tnorthcutt @sambrodie I'm going to leave this issue open and if either of you have a few minutes to test against master in your specific use cases, that would be awesome.

So I've got some slightly different results, but I actually think what I'm experiencing is more desirable behavior:

Custom add to cart link, linking to the alternate cart, with redirect to checkout checked: Results in The alternate checkout with the item in the cart.

Custom add to cart link, linking to alternate cart, with redirect to checkout unchecked: Also results in being at the alternate checkout with the item in the cart.

So the item is being added to the cart for me now in all cases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julien731 picture julien731  路  5Comments

JJJ picture JJJ  路  5Comments

DrewAPicture picture DrewAPicture  路  5Comments

colomet picture colomet  路  4Comments

DevinWalker picture DevinWalker  路  6Comments