Method Auto-Select
This feature is currently flagged as "Experimental".
Admin Configuration Options
There are a number of admin configuration options related to this feature. As always these can be found by logging into
the admin and navigating to Stores -> Settings -> Configuration -> Hyvä Themes -> Checkout
.
Enable First Available Payment Method Automatically
Path: Developer -> Experimental
Default Value: No
Enabling this option will see the first available payment method being pre-selected when the customer arrives at the payment step of the checkout. Payment method availability is evaluated when the customer initialises the checkout for the first time with their current checkout session.
If the customer selects another payment method or chooses to navigate away from the checkout and then return will NOT cause their previously selected payment method to change. Similarly, should the list of available payment methods be updated dynamically during the customer's checkout journey, the auto-selection feature will NOT cause the payment method selection to update (even if the first method in the list is now different) unless there is only a single payment method available.
Enable First Available Shipping Method Automatically
Path: Developer -> Experimental
Default Value: No
Enabling this option will see the first available shipping method being pre-selected when the customer arrives at the shipping step of the checkout. Shipping method availability is evaluated when the customer initialises the checkout for the first time with their current checkout session.
If the customer selects another shipping method or chooses to navigate away from the checkout and then return will NOT cause their previously selected shipping method to change. Similarly, should the list of available shipping methods be updated dynamically during the customer's checkout journey, the auto-selection feature will NOT cause the shipping method selection to update - even if the first method in the list is now different.
Implementation Notes
Checkout Initialisation
The checkout is only initialised once per checkout session thanks to the
Hyva\Checkout\Controller\Index\Index::initCheckout()
function.
Auto-Selection
The code that handles the generic method auto-selection can be
found in the Hyva\Checkout\Observer\Frontend\HyvaCheckoutHyvaCheckoutInitAfter
observer while the code that will
auto-select a payment method when it is the only one available can be found in the
Hyva\Checkout\Magewire\Checkout\Payment\MethodList
component's boot()
function. This dynamic auto-selection for
methods with only a single choice has only currently been implemented for payment methods because of the
Zero Subtotal Checkout feature - if a use case for dynamic shipping method availability
is discovered then this feature may be expanded to also cover shipping methods.