I'm trying to check whether product has custom options or not in code (my code runs sales_order_place_after
event).
I have try below code but it does not returning anything.
$product->hasCustomOptions()
and
$product->hasOptions()
Please let me know what I'm missing.
Adding customizable options to a product is an easy way to offer a selection of options with a variety of text, selection, and date input types. Customizable options are a good solution if your inventory needs are simple.
a a practice which by long-established usage has come to have the force of law. b such practices collectively (esp. in the phrase custom and practice) 4 habitual patronage, esp. of a shop or business.
I've encountered this error more times than I care to count. Either $_product->hasOptions()
or $_product->hasCustomOptions()
always returns false
. I still don't know why this error occurs.
Anyway, you can get the same result by doing the following. For configurable products:
<?php if ( $_product->getData('has_options') ): ?>
<!-- do something -->
<?php endif; ?>
And to get the same result for simple products with custom options:
<?php if ( $_product->getData('has_options') && ($_product->getTypeID() == 'simple') ): ?>
<!-- do something -->
<?php endif; ?>
I hope that helps a future adventurer!
EDIT
The solution above does not work in loops when the flat category data option is enabled in Magento, and we don't want to reload the product inside the foreach loop!!
Instead, we can check for custom options using the following singleton inside the loop:
$opts = Mage::getSingleton('catalog/product_option')->getProductOptionCollection($_product);
$optsSize = $opts->getSize();
if ( $optsSize ) {
... // go go go
}
use the method $product->getHasOptions()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With