Skip to content

How to show non-required custom options of associated products on a configurable product, after all options are selected?

I have a Magento site that works on sync with another site hosted on another server (Not a Magento site). On my site, after choosing a specific variation of a configurable product, an api call has to be made to the external server for price for that specific combination, and alongside that I receive the additional charges required for fast shipping benefits.
I am successfully calling the api to fetch price, and initially I thought of adding the shipping prices to custom options of children products for the selected combination of attributes.

I came to know Magento does not allow custom options for children products of configurable products, if it is set as required, as seen here.

MagentoCatalogModelProductOptionSaveHandler

private function processOptionsSaving(array $options, bool $hasChangedSku, ProductInterface $product): void
    {
        $isProductHasRelations = $this->isProductHasRelations($product);
        /** @var ProductCustomOptionInterface $option */
        foreach ($options as $option) {
            if (!$isProductHasRelations && $option->getIsRequire()) {
                $message = 'Required custom options cannot be added to a simple product'
                    . ' that is a part of a composite product.';
                throw new CouldNotSaveException(__($message));
            }

            if ($hasChangedSku && $option->hasData('product_sku')) {
                $option->setProductSku($product->getSku());
            }
            $this->optionRepository->save($option);
        }
    }

But if the option is not required, it is allowed to add. But it seems Magento has no functionality to show this custom option on the parent product page.

What I am trying to achieve is , after selecting all the configurable options of a product, if the simple product with that options has any custom option, show a block with that options , and the user can select an option from there which will add to the product price.

Is there any easy way to do this using existing functionality of custom options ? Or that has to be done custom completely ?