You can delete/remove the specific Bundle options by option id in Magento 2.
Bundle product has multiple options generated and if you want to remove some options from the product, You can remove it programmatically using option id and Bundle SKU.
Just instantiate the repository interface to the constructor of the model class,
Magento\Bundle\Api\ProductOptionRepositoryInterface and use the deleteById() method to delete options.
<?php namespace Jesadiya\RemoveOption\Model; use Exception; use Psr\Log\LoggerInterface; use Magento\Bundle\Api\ProductOptionRepositoryInterface; class RemoveOption { /** * @var ProductOptionRepositoryInterface */ private $productOptionRepository; public function __construct( ProductOptionRepositoryInterface $productOptionRepository ) { $this->productOptionRepository = $productOptionRepository; } /** * result * * @return bool */ public function removeBundleOption(): bool { $optionId = 1; $sku = '24-WG080'; $isOptionRemoved = false; try { $isOptionRemoved = $this->productOptionRepository->deleteById($sku, $optionId); } catch (Exception $exception) { throw new Exception($exception->getMessage()); } return $isOptionRemoved; } }
In the above method, You need to pass SKU is Bundle Parent Product SKU and option id you want to delete option from the bundle item.
Output:
Boolean
If Bundle product SKU and option id passed correct, Result will be true otherwise error thrown.