I have adjusted my shopify website that customers need to authentificate with their login to buy any products (crucial for our operations, cannot be changed).
we have a problem in case of the following senario:
1/ Customer add products in its cart before authentifying itself
We need that after its authentification the customer get directed to its cart, and then he has to click (again) on the button “check out” and get to the final payment page.
I need to do a page redirection as important information (up-to-dates discount codes related to the customer tag of the customer that authentificated) appear on the cart page only after customer authentification, and in the scenario described above the customer eligible to the discount codes won’t see them.
This redirection isn’t supported natively in Shopify, but it can be done with custom code using JavaScript and Liquid. However, it’s a bit complex and time-consuming to implement properly.
An easier option is using an app that supports login flow control. Here are a few you can check out:
Helium Customer Fields
B2B Login/Lock Access
EasyLockdown ‑ Access Control
These can help with redirection or restricting access before login.
I checked out the website and noticed that the checkout button was taking the user to the Shopify login page but with a redirect after login set to the destination as “/checkout” since that’s the original destination of the user in this case when pressing the button.
@Legval and possibly others who may stumble across this thread later down the line. Here’s how we fixed the issue mentioned and achieved the user behavior requested.
Check if the customer is logged in, If yes - show the theme’s default checkout button as is.
If customer is not logged in, show a custom button with a redirect to the “/cart” after the user completes the login.
Here’s the before code
{%- when 'buttons' -%}
{%- if additional_checkout_buttons and block.settings.show_dynamic_checkout -%}
{{ content_for_additional_checkout_buttons }}
{%- endif -%}
Here’s the after code
{%- when 'buttons' -%}
{% if customer %}
{% else %}
{{ 'sections.cart.checkout' | t }}
{% endif %}
{%- if additional_checkout_buttons and block.settings.show_dynamic_checkout -%}
{{ content_for_additional_checkout_buttons }}
{%- endif -%}
You can check out the Shopify docs that detail how the redirection works for new customer accounts.