Recently, a client requested that their existing Cartthrob site now allow guest checkouts.
Currently it’s using a multi-page checkout.
One page uses {exp:cartthrob:save_customer_info_form}
and the next uses {exp:cartthrob:checkout_form}
.
The problem lies on the first page.
Previously I populated the form with the user’s details if they had it saved in their account, using Solspace User’s {exp:user:stats}
tag.
But now I need to support guest checkouts. The problem is that the {exp:user:stats}
tag will hide its contents if the user is logged out.
So I basically repeat the code, but wrapped in the {exp:user:stats}
tag if they are logged in. (This feels like the wrong way to do this, so if you have an alternative I’d love to hear it.)
{if logged_in}
{exp:user:stats}
{exp:cartthrob:save_customer_info_form required="..." return="cart/payment"}
{var_checkout_fields}
<input type="submit" class="button" value="Next Step" />
{/exp:cartthrob:save_customer_info_form}
{/exp:user:stats}
{if:else}
{exp:cartthrob:save_customer_info_form required="..." return="cart/payment"}
{var_checkout_fields}
<input type="submit" class="button" value="Next Step" />
{/exp:cartthrob:save_customer_info_form}
{/if}
Originally, the code was just what was inside the first conditional.
The form is displayed correctly for members and guests, but only members are able to proceed to the next page. When a guest hits submit, the page is just reloaded.
The Cartthrob setting “User must be logged in” is set to “no”, and I have set the appropriate member id for guest checkouts.