Home » Magento6 July 2015

Magento: Add / Delete / View Custom Options of Product Programmatically

Custom options on Magento products are designed to make simple products function like a configurable product with different choosing options like color, size, etc. before purchasing the product.

In this tutorial, I present the code to create/add, view, and delete custom options of a product in Magento.

ADD CUSTOM OPTIONS

In the following example code, I am adding custom option with title ‘Color’ and I have added two values to it ‘Red’ and ‘Gold’.

You can now see the following custom options when you edit your product in admin:

product custom options

DISPLAY CUSTOM OPTIONS OF A PRODUCT

DELETE CUSTOM OPTIONS OF A PRODUCT

Hope it helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Ajit Kumar

    Fatal error: Uncaught TypeError: Argument 3 passed to Mage_Catalog_Model_Resource_Abstract::_canUpdateAttribute() must be of the type array, null given in app/code/core/Mage/Eav/Model/Entity/Abstract.php.

    I am getting this error while adding custom options in magento 1.9.2

  • Ajit Kumar

    Resolved. Had to change the store as admin store temporarily.

  • Richard Wendrock

    I am trying to use your code to loop through all of the custom options in a specific product in Magento 1.9.3.1. when I get the $customOptions and try to print_r the result, nothing is displayed.
    I am doing this slightly different than your example by looping through all of the products in a category.
    $categoryid = 11; // Build Your Own DIY Handlebar Kit

    $category = new Mage_Catalog_Model_Category();
    $category->load($categoryid);
    $collection = $category->getProductCollection();
    $collection->addAttributeToSelect(‘*’);
    $collection->addAttributeToSort(‘sku’, ‘ASC’);
    $count=0;
    foreach ($collection as $_product) {

    $Name=$_product->getName();
    $sku=$_product->getSku();
    $status=$_product->getStatus();
    echo “Sku:” . $sku . ” ~ ” . $Name . “”;
    $customOptions=$_product->getOptions();
    if ($count==0) {
    echo “Displaying Custom Options”;
    print_r($customOptions);
    $count=1;
    }
    Do you see anything wrong with that logic?
    Thanks Ahead of time for your help…

  • I am trying to use your code to loop through all of the custom options in a specific product in Magento 1.9.3.1. when I get the $customOptions and try to print_r the result, nothing is displayed.
    I am doing this slightly different than your example by looping through all of the products in a category.
    $categoryid = 11; // Build Your Own DIY Handlebar Kit

    $category = new Mage_Catalog_Model_Category();
    $category->load($categoryid);
    $collection = $category->getProductCollection();
    $collection->addAttributeToSelect(‘*’);
    $collection->addAttributeToSort(‘sku’, ‘ASC’);
    $count=0;
    foreach ($collection as $_product) {

    $Name=$_product->getName();
    $sku=$_product->getSku();
    $status=$_product->getStatus();
    echo “Sku:” . $sku . ” ~ ” . $Name . “;
    $customOptions=$_product->getOptions();
    if ($count==0) {
    echo “Displaying Custom Options”;
    print_r($customOptions);
    $count=1; // display only once
    }
    Do you see anything wrong with that logic?
    Thanks Ahead of time for your help…