Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

How to delete custom attribute options in Magento 2

Here we will learn, how to delete custom attribute options programmatically in magento 2.
Use following code to remove the attribute options in Magento2.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$attributeId = 487; // Id of attribute
$attributeModel = $objectManager->create('Magento\Customer\Model\Attribute')->load($attributeId);
$data = [];
$options = $attributeModel->getSource()->getAllOptions(); //get all options
foreach ($options as $value) {
    if (is_numeric($value['value'])) {
        $data['option']['delete'][$value['value']] = 1;
        $data['option']['value'][$value['value']] = $value['label'];
    }
}
$attributeModel->addData($data);
$attributeModel->save();
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home