How to check Product has custom options in Magento 2?

You can check if a product has a custom option exists (hasOptions()) or not in Magento 2 by Product Object.

Some product type contains options like Bundle and Configurable while Simple, Virtual, Grouped, Downloadable and gift card doesn’t support options.

You can check product has options by loading Product object with $product->hasOptions() function.

Call from the template or any PHP class,
echo $productHasOptions = $this->hasOptionsProduct();

Sample data with different type of products,
’24-WG080′ = Bundle (HasOptions 1)
‘MJ08’ = Configurable (HasOptions 1)
’24-WG085_Group’ = Grouped (HasOptions 0)
‘240-LV04’ = Downloadable (HasOptions 0)
’24-MB01′ = Simple (HasOptions 0)
Virtual product (HasOptions 0)

Output:
boolean

Leave a Reply