Setting Default Product Variant
You can control which variant is selected by default in your product templates by implementing thegetDefaultProductVariant hook in your JavaScript template object.
Implementation
Add the following hook to your JavaScript template object:Customization Examples
You can customize the logic insidegetDefaultProductVariant to select different variants based on your requirements. Here are some practical examples:
Parameters
The hook receives the following parameter:product(Object): The full product object containing all product data including variants
Return Value
The hook should return the variant ID (number) of the variant that you want to be selected by default when the product page loads.If the
getDefaultProductVariant function returns null, it will have no effect on the variant selection in the store. The default variant selection behavior will remain unchanged.