6 Steps to Configure Magento 2 Product Custom Options

Getting product options is a feature supported by Magento 2 and it is simple for Magento 2 store owners to add and allow new custom product options. Applying product options for the customer’s choice is also a great way to enhance your current eCommerce capabilities as well as expand the chance to visit all your products.

In order to help you be closer to this setup, please follow the tutorial I am bringing to you and get the product options in Magento 2. This topic will cover 6 steps you need to track.


Product Options

Product Options for Magento 2

Magento 2 Product Options supports store owners to assign options to multiple products quickly.

Check it out!


What are custom product options used for?

When you add custom options to a product in Magento 2, you provide your consumers the choice of selecting product options based on their specific needs rather than relying on product attributes.

With this feature, you can create customizable product options such as creating custom cart price rules, dynamic category rules, and so on. If your purpose is to bring in a versatile experience for your customers, getting custom product options is one of the best ways to achieve it.

Get Product Custom Options Programmatically in Magento 2

Step 1: Create an object manager

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();

Step 2: Generate the product

Generate the product that needs to be assigned custom options.

$product = $_objectManager->get('\Magento\Catalog\Model\Product')->load($id);

Step 3: Custom options

$customOptions = $_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);

Step 4: Configurable Options

$productTypeInstance = $_objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable');
         $productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);

Step 5: Grouped Childs

$typeInstance = $_objectManager->get('Magento\GroupedProduct\Model\Product\Type\Grouped');
         $childs = $typeInstance->getAssociatedProducts($product);

Step 6: Bundle selection

$store_id = $_storeManager->getStore()->getId();
            $options = $_objectManager->get('Magento\Bundle\Model\Option')
         ->getResourceCollection()
                          ->setProductIdFilter($product->getId())
                          ->setPositionOrder();
         $options->joinValues($store_id);
$typeInstance = $_objectManager->get('Magento\Bundle\Model\Product\Type');
$selections = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);

When completing all, this means the product options are active on your Magento 2 store.

How to Configure Magento 2 Custom Options from the Backend?

  • Go to Catalog > Products then choose the product you want to configure custom options or add a new one by clicking on the Add New Product button.

Product grid

  • Scroll down to find the Customizable Options section > choose Add Option.
  • Name the option title and type
  • Decide whether you want it to be required or not by ticking on the Required check box
  • Press Add Value then fill out the below fields:

    • Title
    • Price
    • Price Type
    • SKU

Customizable Options

  • Finally, save your configuration.
  • Here’s how it looks like on the product page

Product page example

Wrap up

That’s all you need to get custom product options programmatically. I hope this tutorial is helpful and works on your Magento 2 store. If you are looking for an extension to help you assign options to multiple products quickly and conveniently via templates, take a look at Product Options for Magento 2. Feel free to contact us for more details.

Image Description
Sam is the CEO & co-founder of Mageplaza, a company established to support Magento merchants with different powerful tools and resources. Sam Nguyen is also the CEO & founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore – aiming to support more than a million online businesses to grow and develop.

People also searched for

  • magento 2 how to get product options
  • 2.3.x, 2.4.x
x