Magento 2 – Add Custom Price Type in Customizable Options

custom-optionsmagento2price

I would like to create a new custom option price type for the products in the 'Customizable Options' section. Could you please help me out how to add? Is it a possible to add this in Magento 2.x ? if possible could you please explain how to add.

Please find the below screenshot:

screenshot

Best Answer

Create a plugin for that. So you need to create new module Or add following code into your existing module.

SR/StackExchange/etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Config\Source\Product\Options\Price">
        <plugin name="sr_stackexchange_add_price_type" type="SR\StackExchange\Plugin\Catalog\Model\Config\Source\Product\Options\Price" sortOrder="1"/>
    </type>
</config>

SR/StackExchange/Plugin/Catalog/Model/Config/Source/Product/Options/Price.php

namespace SR\StackExchange\Plugin\Catalog\Model\Config\Source\Product\Options;

class Price
{
    /**
     * {@inheritdoc}
     *
     * @codeCoverageIgnore
     */
    public function afterToOptionArray(
        \Magento\Catalog\Model\Config\Source\Product\Options\Price $subject,
        array  $priceTypeOption
    ){
        $priceTypeOption[] = ['value' => 'new_type', 'label' => __('New Type')];
        return $priceTypeOption;
    }
}

Clear magento cache.

Related Topic