For testing purposes, I went the js route and injected the data-lang attribute via jQuery as seen on the attached img. A custom js function (fnHideCalLangOptions()) is used to display all relevant language options included in attribute data-lang.
Essentially, the code prepends the custom fn to the current HK function (hikashopUpdateVariant(this)) in the onchange attribute ie:
<select id="hikashop_product_characteristic_9"
onchange="fnHideCalLangOptions($(this));return hikashopUpdateVariant(this);" .... >
<option selected="selected" value="14" data-lang="18, 19">Switzerland</option>
...
</select>
Question:
This quick fix works, but I wonder if it may possibly conflict with future HK releases. If so, could you please suggest alternative approaches to tackle this issue?
TIA for any hints/references.
jQuery code:/* ---------------------------------------------------
Adds data-lang attribute to calendar theme product characteristics. The attr contains the PK's of the associated theme languages. Assumes cal theme characteristics are ordered (ie 1. CH, 2. Splendor of Nature, etc.)
child 0: Switzerland 1. N4 (de/fr/en) 2. N6 (en)
child 1: Splendor: 1. N4 (de/fr/en) 2. N6 (en) 3. N7 (de/fr) 4. N8 (de/fr/it)
*/
jQuery(function ($) {
// Add attribute data-lang to cal theme prod char ddn: #hikashop_product_characteristic_9
var $calthemeDdn=$('#hikashop_product_characteristic_9');
// Add data-lang attribute if ddn exists.
if ( $calthemeDdn.length ) {
$calthemeDdn.children().eq(0).attr('data-lang', '18, 19');
$calthemeDdn.children().eq(1).attr('data-lang', '18, 19, 20, 21');
// Prepend custom "fnHideCalLangOptions()" to current HK onchange fn. Pass selected cal theme option to custom fn.
var fnExp= $calthemeDdn.attr('onchange');
fnExp= "fnHideCalLangOptions($(this));" + fnExp;
$calthemeDdn.attr('onchange', fnExp);
}
});
function fnHideCalLangOptions($ddn){
// Displays all cal language options associated to selected cal theme $ddn.
var data_lang = jQuery('#hikashop_product_characteristic_9').find("option[value='" + $ddn.value + "']").eq(0).attr("data-lang"); // ie "18, 19, 20, 21"
var $calLangDdn=jQuery('#hikashop_product_characteristic_22');
// Show only cal language options associated to selected theme.
$calLangDdn.children().hide().each(function (idx, opt) {
if (data_lang.indexOf(this.value) > -1) {
jQuery(opt).show();
}
});
}