Add Rough Magento2 example below to pre-select custom parameters by name = value in:
/www/mysite/app/design/frontend/mycompany/mytheme/Magento_Catalog/templates/product/view/options.phtml
The code below displays the option label and the text value of the selection. And it depends on your topic structure. Example below for Luma.
It expects the following format in URL
product.html?SelectLabel=OptionValue&SelectLabel=OptionValue
This does not take into account multilingualism, etc., you can easily adapt it, instead find the identifier of the choice and the identifier of the option, which will be a more accurate replacement
$(label).parents().eq(1).find('select option:contains('+arr[k]+')').attr('selected', true);
with (untested)
$("#"+k+" option[id='"+arr[k]+"']").attr("selected", "selected");
<script> require(['jquery'],function($){ $(document).ready(function(){ function getJsonFromUrl() { var query = location.search.substr(1); var result = {}; query.split("&").forEach(function(part) { var item = part.split("="); result[item[0]] = decodeURIComponent(item[1]); }); return result; } var arr = getJsonFromUrl(); for (var k in arr){ if (arr.hasOwnProperty(k)) {
Joel davey
source share