Magento Display Dynamic SKU for configurable Product... Don't Display until all options are selected

Magento Display Dynamic SKU for configurable Product... Don't Display until all options are selected

October 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Display Dynamic SKU for configurable Product... Don't Display until all options are selected

Hiding Configurable Product SKU Until All Options Are Selected

As an experienced Magento developer, I often encounter requests for custom functionality like displaying dynamic SKUs for configurable products only after all options have been selected by the customer. In this post, we’ll explore a solution to this common challenge using a combination of JavaScript and PHP.

The Current Setup: Almost There!

The provided code snippet is already quite advanced. It successfully retrieves the SKUs of all associated simple products for a given configurable product:

<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

foreach($itemId as $val){
    foreach($val as $k => $v){
        echo 'Skus['.$count.'] = "'.$v.'";'. "\n";
        $count++;
    };
}
?>

This generates an array of SKUs that can be accessed via JavaScript to dynamically update the displayed SKU based on the selected options.

However, as you’ve noticed, there’s a small issue: The first SKU is currently being displayed before any options are selected. To fix this and hide the SKU until all options are chosen, we need to make some adjustments to both the JavaScript and PHP files involved.

Modifying the Configurable Options File

Let’s open the configurable.phtml file located at app/design/frontend/rwd/default/template/catalog/product/view/type/options/configurable.phtml. We’ll add a new div element to hold our dynamic SKU:

<div id="dynamic-sku" style="display: none;">SKU: &lt;span id="selected-sku">&lt;/span>&lt;/div>

Next, we need to modify the JavaScript code. Instead of directly setting the content of #productcode, we’ll use an event listener for the change event on all select elements:

$j(document).ready(function(){
    $j("select").change(function() {
        var allSelected = true;
        $j("select").each(function() {
            if ($j(this).find(":selected").length === 0) {
                allSelected = false;
                return false;
            }
        });

        if (allSelected) {
            // Get the selected SKU position
            var position = $j("#attribute&lt;?php echo $_attribute->getAttributeId() ?&gt; option").index($j("#attribute&lt;?php echo $_attribute->getAttributeId() ?&gt; option:selected"));

            // Set the dynamic SKU
            $j("#selected-sku").html(Skus[position]);

            // Show the dynamic SKU div
            $j("#dynamic-sku").show();
        } else {
            // Hide the dynamic SKU div if not all options are selected
            $j("#dynamic-sku").hide();
            $j("#selected-sku").html("");
        }
    });
});

Updating the Product View File

Now, let’s modify the view.phtml file located at app/design/frontend/rwd/default/template/catalog/product/view/view.phtml. We need to replace or add the following section:

<div id="productcode">
  <div id="dynamic-sku" style="display: none;">SKU: &lt;span id="selected-sku">&lt;/span>&lt;/div>
</div>

The Final Result

With these modifications, the dynamic SKU will now remain hidden until all configurable options are selected by the customer. If they go back and change their selection for any reason, the SKU div will immediately be hidden again.

Remember to clear your cache after making these changes:

php magento cache:clean

This solution provides a clean and efficient way of managing dynamic SKUs for configurable products while ensuring a seamless user experience. It demonstrates how PHP and JavaScript can work together to create custom Magento functionality tailored to specific business needs.

For more advanced customization tips and best practices, feel free to explore our other posts on Laravel Company.

Catalog Themes Configuration Customers

Our network