- there is no need to override Hook.php if you are using PS 8.*
- always back up the /classes/override/Hook.php before editing
- use notepad or similar clean text editor NOT Word
- if unsure, contact your webmaster
1) this is content of /override/classes/Hook.php created by the Unclaimed Orders module:
class Hook extends HookCore
{
public static function getHookModuleExecList($hookName = null)
{
$modulesToInvoke = parent::getHookModuleExecList($hookName);
return self::filterPaymentModules($hookName, $modulesToInvoke);
}
public static function filterPaymentModules($hookName, $modulesToInvoke)
{
if (Tools::version_compare(_PS_VERSION_, '1.7.0', '>') && $hookName != 'paymentOptions') {
return $modulesToInvoke;
}
if (Tools::version_compare(_PS_VERSION_, '1.7.0', '<') && $hookName != 'displayPayment') {
return $modulesToInvoke;
}
if (!empty($modulesToInvoke)) {
if (Module::isEnabled('vm_unclaimed')) {
$instance = Module::getInstanceByName('vm_unclaimed');
$modulesToInvoke = (new vm_unclaimed\classes\PaymentFilter())->filterPaymentModules($instance, $modulesToInvoke, true);
}
}
return !empty($modulesToInvoke) ? $modulesToInvoke : false;
}
}
2) In this example the function getHookModuleExecListwas already overriden by the dm_cookies module. Therefore the /override/classes/Hook.php was manually edited as folow (modified or newly added code in red):
class Hook extends HookCore
{
/*
* module: dm_cookies
* date: 2023-08-23 09:50:06
* version: 3.0.4
*/
public static function getHookModuleExecList($hook_name = null)
{
$hooks = parent::getHookModuleExecList($hook_name);
$context = Context::getContext();
if($hooks AND Configuration::get('DM_COOKIES_ACTIVE') == 1 AND isset($context->cart) AND isset($context->controller->controller_type) AND ($context->controller->controller_type == 'front' OR $context->controller->controller_type == 'modulefront'))
{
if(isset($_COOKIE['DmCookiesAccepted']) AND isset($_COOKIE['DmCookiesAnalytics']) AND isset($_COOKIE['DmCookiesMarketing']))
{
$check_allowed_group_1 = (int)((string)$_COOKIE['DmCookiesAnalytics'] == 'true' ? 1 : 0);
$check_allowed_group_2 = (int)((string)$_COOKIE['DmCookiesMarketing'] == 'true' ? 1 : 0);
}
else
{
$check_allowed_group_1 = 0;
$check_allowed_group_2 = 0;
}
if($check_allowed_group_1 != 1)
{
$blocked_module_group_1 = explode(',', Configuration::get('DM_COOKIES_ANALYTICS_BLOCKED'));
foreach($hooks as $key => $value)
{
if (in_array($value['module'], $blocked_module_group_1))
{
unset($hooks[$key]);
}
}
}
if($check_allowed_group_2 != 1)
{
$blocked_module_group_2 = explode(',', Configuration::get('DM_COOKIES_MARKETING_BLOCKED'));
foreach($hooks as $key => $value)
{
if (in_array($value['module'], $blocked_module_group_2))
{
unset($hooks[$key]);
}
}
}
}
// note that the first parametr name is $hook_name in this specific case
return self::filterPaymentModules($hook_name, $hooks);
}
public static function filterPaymentModules($hookName, $modulesToInvoke)
{
if (Tools::version_compare(_PS_VERSION_, '1.7.0', '>') && $hookName != 'paymentOptions') {
return $modulesToInvoke;
}
if (Tools::version_compare(_PS_VERSION_, '1.7.0', '<') && $hookName != 'displayPayment') {
return $modulesToInvoke;
}
if (!empty($modulesToInvoke)) {
if (Module::isEnabled('vm_unclaimed')) {
$instance = Module::getInstanceByName('vm_unclaimed');
$modulesToInvoke = (new vm_unclaimed\classes\PaymentFilter())->filterPaymentModules($instance, $modulesToInvoke, true);
}
}
return !empty($modulesToInvoke) ? $modulesToInvoke : false;
}
}