Skip to content

Magento 2 configurable product how the child options are filtered based on previous selected option

In a configurable product, Magento automatically filters the options based on previous selected option. E.g If I have size and color as super attribute, and I don’t have XL size for red color, when I select red in PDP, the XL option is removed from following selection.
I know this works from configurable.js file. But I am struggling to figure out how this is done.

In _configureElement, if I log element.nextSetting, it shows the following option already filtered.

Also is there any possibility to do this using php ?