{"id":26041,"date":"2026-03-06T18:00:00","date_gmt":"2026-03-06T12:30:00","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/?p=26041"},"modified":"2026-03-06T17:05:35","modified_gmt":"2026-03-06T11:35:35","slug":"how-to-add-custom-button-magento-2-admin-ui-component-form-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/how-to-add-custom-button-magento-2-admin-ui-component-form-2\/","title":{"rendered":"How to Add a Custom Button to Magento 2 Admin UI Component Form (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You require specialized workflows that go beyond default functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of them is adding a custom button to Magento 2 Admin UI component form.&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It helps to streamline complex tasks such as syncing products with third-party APIs, triggering custom price calculations, or sending a product through an approval workflow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the simple steps to adding a custom button to trigger these backend processes directly from the admin interface.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Add a Custom Button to Magento 2 Admin UI Component Form<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We will create a Generate Custom SKU button.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create UI Component XML<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the code below in the <strong>product_form.xml<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">File located at&nbsp; <strong>app\/code\/Vendor\/Module\/view\/adminhtml\/ui_component<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;form xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Ui:etc\/ui_configuration.xsd\">\n\n    &lt;settings>\n        &lt;buttons>\n            &lt;button name=\"generate_custom_sku\"\n                    class=\"Vendor\\Module\\Block\\Adminhtml\\Product\\Edit\\Button\\GenerateSku\"\/>\n        &lt;\/buttons>\n    &lt;\/settings>\n\n&lt;\/form>\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create a button in the GenerateSku.php file<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create the GenerateSku.php file at the location app\/code\/Vendor\/Module\/Block\/Adminhtml\/Product\/Edit\/Button and use the code below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Module\\Block\\Adminhtml\\Product\\Edit\\Button;\n\nuse Magento\\Framework\\View\\Element\\UiComponent\\Control\\ButtonProviderInterface;\nuse Magento\\Framework\\Registry;\n\nclass GenerateSku implements ButtonProviderInterface\n{\n    protected $registry;\n\n    public function __construct(\n        Registry $registry\n    ) {\n        $this->registry = $registry;\n    }\n\n    public function getButtonData()\n    {\n        $product = $this->registry->registry('current_product');\n\n        if (!$product || !$product->getId()) {\n            return [];\n        }\n\n        return [\n            'label' => __('Generate Custom SKU'),\n            'class' => 'primary',\n            'on_click' => \"setLocation('your_custom_controller_url_here')\",\n            'sort_order' => 90,\n        ];\n    }\n}\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: View the Button on Product Edit Page&nbsp;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you can clear the cache and check the product edit page. Your new custom button will appear in the top-right corner of the product Edit page, like the one below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"340\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2026\/03\/custom_button_to_the_Magento_2_admin-1024x340.png\" alt=\"Custom button in the Magento 2 admin\" class=\"wp-image-26043\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2026\/03\/custom_button_to_the_Magento_2_admin-1024x340.png 1024w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2026\/03\/custom_button_to_the_Magento_2_admin-300x100.png 300w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2026\/03\/custom_button_to_the_Magento_2_admin-768x255.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2026\/03\/custom_button_to_the_Magento_2_admin-1536x510.png 1536w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2026\/03\/custom_button_to_the_Magento_2_admin-2048x680.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all!<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adding a custom button to the Magento 2 admin UI component form is a clean and scalable way to extend functionality without modifying core files.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You require specialized workflows that go beyond default functionality. One of them is adding a custom button to Magento 2 Admin UI component form.&nbsp;&nbsp; It&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-26041","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/26041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=26041"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/26041\/revisions"}],"predecessor-version":[{"id":26045,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/26041\/revisions\/26045"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=26041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=26041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=26041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}