I am new to this Magento platform.
I want to create a custom widget to retrieve the price so that I can use it just by calling the widget on the front page.
May anyone help me?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityYou can create one block file in your custom module like
path app/code/YourVendor/YourModule/Block/PriceWidget.php
<?php
namespace YourVendor\YourModule\Block;
use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;
class PriceWidget extends Template implements BlockInterface
{
// Implement logic here to retrieve the product price.
}
create widget.xml in the following path
app/code/YourVendor/YourModule/etc/widget.xml
<?xml version="1.0"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:widget:1.0">
<widget id="yourmodule_price_widget" class="YourVendor\YourModule\Block\PriceWidget">
<label translate="true">Price Widget</label>
<description translate="true">Display product price.</description>
<parameters>
<!-- Add widget parameters here if needed -->
</parameters>
</widget>
</widgets>
In the Magento Admin Panel, you can now insert your custom widget into a CMS page or block. Go to the CMS page or block where you want to display the price and use the widget insertion tool to add your custom widget.