As I asked in the question I want to get the SKU of a simple product selected by the option in configurable product details page.
How can I capture the SKU?
Tried in this way, but not possible to capture the selected options SKU
$product_id = $block->getProduct()->getId();//Configurable product ID
$configProduct = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
$_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);
foreach ($_children as $child){
echo "Here are your child Product Ids ".$child->getID()."-:-".$child->getSku()."</br>";
}
echo "count: ".count($_children);
Best Answer
This the script you need to add on your phtml file:
Create a module with name Vendor_Module.
Also you need to create a routes.xml for frontend like below:
and add the following code to it.
Now create one controller to below path:
with below content:
You will get the sku in your ajax response. You can now do whatever you want with the sku.
Hope this helps!