{"id":13624,"date":"2025-03-18T10:41:58","date_gmt":"2025-03-18T05:11:58","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=13624"},"modified":"2025-07-09T16:45:01","modified_gmt":"2025-07-09T11:15:01","slug":"create-custom-prestashop-module","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/prestashop-tutorials\/create-custom-prestashop-module\/","title":{"rendered":"How to Create a Custom PrestaShop Module"},"content":{"rendered":"<p data-pm-slice=\"1 1 []\">Creating a custom module in PrestaShop allows you to extend its functionality without modifying the core files. In this tutorial, we will go step by step to create a basic custom module for PrestaShop 1.7 and later versions.<\/p>\n<h3>Step 1: Create the Module Folder and Files<\/h3>\n<p>Navigate to the <code>modules<\/code> directory of your PrestaShop installation and create a new folder for your module. Let&#8217;s name it <code>mycustommodule<\/code>.<\/p>\n<p>Inside the <code>mycustommodule<\/code> folder, create a PHP file named <code>mycustommodule.php<\/code>. This will be the main file for your module.<\/p>\n<h3>Step 2: Define the Module Class<\/h3>\n<p>Open <code>mycustommodule.php<\/code> and add the following code:<\/p>\n<pre><code>&lt;?php\r\nif (!defined('_PS_VERSION_')) {\r\n    exit;\r\n}\r\n\r\nclass MyCustomModule extends Module\r\n{\r\n    public function __construct()\r\n    {\r\n        $this-&gt;name = 'mycustommodule';\r\n        $this-&gt;tab = 'front_office_features';\r\n        $this-&gt;version = '1.0.0';\r\n        $this-&gt;author = 'Your Name';\r\n        $this-&gt;need_instance = 0;\r\n        \r\n        parent::__construct();\r\n\r\n        $this-&gt;displayName = $this-&gt;l('My Custom Module');\r\n        $this-&gt;description = $this-&gt;l('A simple custom module for PrestaShop.');\r\n    }\r\n}<\/code><\/pre>\n<h3>Step 3: Install and Uninstall Methods<\/h3>\n<p>Add the following methods inside the <code>MyCustomModule<\/code> class to handle installation and uninstallation:<\/p>\n<pre><code>public function install()\r\n{\r\n    return parent::install() &amp;&amp; Configuration::updateValue('MYCUSTOMMODULE_TEXT', 'Default Value');\r\n}\r\n\r\npublic function uninstall()\r\n{\r\n    return parent::uninstall() &amp;&amp; Configuration::deleteByName('MYCUSTOMMODULE_TEXT');\r\n}<\/code><\/pre>\n<h3>Step 4: Register a Hook<\/h3>\n<p>To display content in a specific part of your PrestaShop store, register a hook. Let&#8217;s hook into the <code>displayHome<\/code> hook to show a message on the homepage:<\/p>\n<pre><code>public function install()\r\n{\r\n    return parent::install() &amp;&amp; $this-&gt;registerHook('displayHome');\r\n}\r\n\r\npublic function hookDisplayHome($params)\r\n{\r\n    return '&lt;p&gt;Welcome to my custom module!&lt;\/p&gt;';\r\n}<\/code><\/pre>\n<h3>Step 5: Create a Basic Configuration Page<\/h3>\n<p>To allow users to modify module settings, add the <code>getContent<\/code> method for an admin configuration form:<\/p>\n<pre><code>public function getContent()\r\n{\r\n    $output = '';\r\n    if (Tools::isSubmit('submitMyCustomModule')) {\r\n        $customText = Tools::getValue('MYCUSTOMMODULE_TEXT');\r\n        Configuration::updateValue('MYCUSTOMMODULE_TEXT', $customText);\r\n        $output .= $this-&gt;displayConfirmation('Settings updated');\r\n    }\r\n    \r\n    return $output . $this-&gt;renderForm();\r\n}\r\n\r\nprivate function renderForm()\r\n{\r\n    $fieldsForm = [\r\n        'form' =&gt; [\r\n            'legend' =&gt; [\r\n                'title' =&gt; $this-&gt;l('Settings'),\r\n            ],\r\n            'input' =&gt; [\r\n                [\r\n                    'type' =&gt; 'text',\r\n                    'label' =&gt; $this-&gt;l('Custom Text'),\r\n                    'name' =&gt; 'MYCUSTOMMODULE_TEXT',\r\n                    'size' =&gt; 20,\r\n                    'required' =&gt; true,\r\n                ]\r\n            ],\r\n            'submit' =&gt; [\r\n                'title' =&gt; $this-&gt;l('Save'),\r\n                'class' =&gt; 'btn btn-default pull-right'\r\n            ]\r\n        ]\r\n    ];\r\n\r\n    $helper = new HelperForm();\r\n    $helper-&gt;table = $this-&gt;table;\r\n    $helper-&gt;default_form_language = (int) Configuration::get('PS_LANG_DEFAULT');\r\n    $helper-&gt;allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;\r\n    $helper-&gt;identifier = $this-&gt;identifier;\r\n    $helper-&gt;submit_action = 'submitMyCustomModule';\r\n    $helper-&gt;currentIndex = AdminController::$currentIndex . '&amp;configure=' . $this-&gt;name;\r\n    $helper-&gt;token = Tools::getAdminTokenLite('AdminModules');\r\n    \r\n    $helper-&gt;fields_value['MYCUSTOMMODULE_TEXT'] = Configuration::get('MYCUSTOMMODULE_TEXT');\r\n\r\n    return $helper-&gt;generateForm([$fieldsForm]);\r\n}<\/code><\/pre>\n<h3>Step 6: Install the Module<\/h3>\n<ol start=\"1\" data-spread=\"false\">\n<li>Zip the <code>mycustommodule<\/code> folder.<\/li>\n<li>Go to <strong>PrestaShop Back Office &gt; Modules &gt; Module Manager<\/strong>.<\/li>\n<li>Click <strong>Upload a module<\/strong> and select your zip file.<\/li>\n<li>Install and activate the module.<\/li>\n<li>Configure the module in the admin panel by modifying the custom text field.<\/li>\n<\/ol>\n<p>Now, your module should display a message on the homepage!<\/p>\n<h3>Conclusion<\/h3>\n<p>This tutorial covered the basics of creating a PrestaShop module, including an admin configuration page. You can extend it further by adding more hooks, a database table, or advanced settings to enhance the module&#8217;s functionality.<\/p>\n<div class=\"angwp_12010 _ning_cont _ning_hidden _ning_outer _align_center responsive\" data-size=\"custom\" data-bid=\"12010\" data-aid=\"0\" style=\"max-width:800px; width:100%;height:inherit;\"><div class=\"_ning_label _left\" style=\"\"><\/div><div class=\"_ning_inner\" style=\"\"><a href=\"https:\/\/www.hiddentechies.com\/blog?_dnlink=12010&t=1777818311\" class=\"strack_cli _ning_link\" target=\"_blank\">&nbsp;<\/a><div class=\"_ning_elmt\"><img decoding=\"async\" src=\"https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/angwp\/items\/12010\/Banner-2.png\" \/><\/div><\/div><\/div><div class=\"clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Creating a custom module in PrestaShop allows you to extend its functionality without modifying the core files. In this tutorial, we will go step by step to create a basic custom module for PrestaShop 1.7 and later versions. Step 1: Create the Module Folder and Files Navigate to the modules directory of your PrestaShop installation&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/prestashop-tutorials\/create-custom-prestashop-module\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":13656,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[221,222,2509,2527,2305,2139,1],"tags":[2540,2548,2542,2545,2541,2547,2546,2543,2544,2539],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/13624"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=13624"}],"version-history":[{"count":4,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/13624\/revisions"}],"predecessor-version":[{"id":13629,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/13624\/revisions\/13629"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/13656"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=13624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=13624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=13624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}