0

I want to display some text next to the price of a product if it has custom options. I have placed some code in final_price.phtml but it doesn't show the message on custom option products.

Can anyone please advise an update to the below to get this working?

<span class="special-price">
    /** Show text if has custom option */ <?php if ($block->hasOptions()):?>
        <?php echo ('from'); ?>
    <?php endif;?> /** Show text if has custom option */
    <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
        'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
        'price_type'        => 'finalPrice',
        'include_container' => true,
        'schema' => $schema
    ]); ?>
</span>
1

2 Answers 2

1

Maybe you try sth like

$block->getSaleableItem()->getTypeInstance()->hasOptions($block->getSaleableItem());
0

You can use the following code -

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

if(count($customOptions) > 0){
  //The product has custom options
}

Reference: https://www.mageplaza.com/how-to-get-product-options-in-magento-2.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.