Magento – How to get simple product id of configurable product on Product details page

magento2product-view

In product details page when user choose like color and size it returns simple product id of thatenter image description here

Best Answer

I have select box at attribute of configurable product. This is what i have done to get simple product id. Put following code in your configurable product phtml file.

 require(["jquery"], function(jQuery) {
      jQuery(".product-options-wrapper select[id^='attribute']").last().on('change', function() {
          setTimeout(function (){
            simpleId=jQuery("input[name=selected_configurable_option]").val();
            alert(simpleId);
          }, 500); 
      });
}); // Required

If you have configurable swatch than it will required minor change in above code.Hope it will help someone.

Thank you

Related Topic