Post by CedSha » Sun Feb 23, 2025 2:35 am

This is a new answer to an old thread here: viewtopic.php?p=223071#p223071
Because it is a simple (but complete) solution, it's posted here.

This is an updated code for V4.1.0.0 so the first value (in order) would be the default one
Pay attention this is a temporary workaround to solve the problem, as any OC update could reset this code !
There is 3 type of option that I wanted default value :
  • radio
  • checkbox
  • select
to do that I edited the file ...catalog/view/template/product/product.twig (I suggest to backup first !)
For the radio I replace

Code: Select all

<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" id="input-option-value-{{ option_value.product_option_value_id }}" class="form-check-input"/>
with

Code: Select all

<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" id="input-option-value-{{ option_value.product_option_value_id }}" class="form-check-input"
				{% if loop.first %}checked{% endif %} />
For the checkbox I replace

Code: Select all

<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" id="input-option-value-{{ option_value.product_option_value_id }}" class="form-check-input"/>
with

Code: Select all

<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" id="input-option-value-{{ option_value.product_option_value_id }}" class="form-check-input"
				{% if loop.first %} checked {% endif %} >
And finally for the select I replace

Code: Select all

<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
with

Code: Select all

<option value="{{ option_value.product_option_value_id }}" {% if loop.first %}selected{% endif %}> {{ option_value.name }}
HTH :)

Image


User avatar
Newbie

Posts

Joined
Mon Sep 18, 2023 1:01 am

Who is online

Users browsing this forum: No registered users and 7 guests