When I create product programmatically I want to set custom attributes value. try to below code but it displays

Uncaught Error: Call to a member function setCustomAttribute()

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('\Magento\Catalog\Model\Product');
$product->setName('Sample Product');
                            'use_config_manage_stock' => 0,
                            'manage_stock' => 1,
                            'is_in_stock' => 1,
                            'qty' => 999999999

You can try below code. where CustomAttribute('custom_attribute') is your attribute code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.