Q:

Magento2 : Get Custom Options from Product Id?

I am trying to get product custom options using next code:
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $_objectManager->get(‘\Magento\Catalog\Model\Product’)->load($id);
$customOptions = $_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);

but its not working for me. It's breaking the page.
Can you please suggest proper solution for it?

A:

To achieve your goal you can use the product repository and the product options repository, like this:
public function __construct(
    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
    \Magento\Catalog\Api\ProductCustomOptionRepositoryInterface $productOptionRepository
) {
    $productId = 14;
    /** @var \Magento\Catalog\Model\Product $product */
    $product = $productRepository->getById($productId);
    $options = $productOptionRepository->getProductOptions($product);
}

Result:

Another way you can load the product and get options directly from it (not better way):
public function __construct(
    \Magento\Catalog\Model\ProductFactory $productFactory
) {
    $productId = 14; // your product id (with options)
    /** @var \Magento\Catalog\Model\Product $product */
    $product = $productFactory->create()->load($productId);
    $options = $product->getOptions();
}

Result:

Or you can use the product options repository:
public function __construct(
    \Magento\Catalog\Model\ProductFactory $productFactory,
    \Magento\Catalog\Api\ProductCustomOptionRepositoryInterface $productOptionRepository
) {
    $productId = 14;
    /** @var \Magento\Catalog\Model\Product $product */
    $product = $productFactory->create()->load($productId);
    $options = $productOptionRepository->getProductOptions($product);
}

And get the same result:

