Opencart cookie and GDPR management for Legal policies in Opencart 4, 3, and 2 versions

In Opencart 4, the cookie and GDPR management are available by default for the legal policies, where you can select the pages for them and show the popup at the footer. You can set them at Admin >> System >> Settings >> Option tab >> Legal carousel tab where you can select the Coolie policy page, GDPR Policy page, and GDPR limit time in days.

Opencart legal cookie GDPR settings

Cookie Policy: Display the Cookie policy as part of the EU Law. 

GDPR Policy: Display the Cookie policy as part of the EU Law. 

GDPR Limit: Limits the number of days before a personal data removal request is performed after its approval. Required for returns and chargebacks and fraud prevention.

General Data Protection Regulation Request page and setting

With the above setting, you can view a GDPR request page that is active on “?route=information/gdpr”. For example, in our Opencart demo, the URL is where you will see the form below:

Opencart GDPR request page

Once you entered the email and choose “Remove Personal Date” to remove, you will see notices like the below:

Warning you will lose access to your account!

  • You will no longer have access to your account.
  • You will no longer have access to your order history, invoices, wishlists, or downloads.
  • Account deletion requests will be processed after 180 days so any fraud detection, chargebacks, or refunds can be processed.
gdpr removal request

When someone submits the request, the administrator gets the lists at Admin >> Customers >> GDPR and you will see like below and from where the admin can approve, deny or delete.

gdpr admin section

Once you set the GDPR settings, you will see the popup at the bottom of the website like the one below:

Opencart cookie bar popup at bottom

Once clicked “Yes, that’s fine!” it will not show the days you set on the GDPR limit, here in our example it is 180 days.

For Opencart 2 and 3, we have  developed a module called “Cookie bar for OpenCart 2 and 3

How to change the Cookie or GDPR text which you see in the popup?

You can change the text of the cookie text “This website uses cookies. For more information click here.” to your desired text. For that you need to login to the Opencart admin section >> Design >> Language Editor >> Add New (blue button)  and enter the following:

Store: Default

Language: English

Route: common/cookie

Key: text_cookie

Default: Auto-filled and not editable

Value: Enter your desired text, we are entering below:
We use cookies to improve your experience with this website. To find out more information about our cookies, please see our <a href=”%s” class=”alert-link modal-link”>Cookies policy</a>

Opencart cookies text language change

Then click Save. You can make changes to the agree and disagree button also, we added two more language changes like below:

Opencart agree disagree button text change for cookie

After these changes, the frontend cookie bar shows like below:

Opencart language changed for cookie bar

In Opencart 4 cookie bar persists, fix the cookie bar to hide once clicked

In Opencart 4 the cookie bar persists even though you click the agree on the button or the disagree button. We have the following fix for now:

Open the catalog/controller/common/cookie.php file and look for confirm method:

public function confirm(): void and find the following lines of code:

$option = [
	'expires' => time() + 60 * 60 * 24 * 365,
	'path' => !empty($_SERVER['PHP_SELF']) ? dirname($_SERVER['PHP_SELF']) . '/' : '',
	'SameSite' => $this->config->get('session_samesite'),

From the above code, remove dirname($_SERVER[‘PHP_SELF’]) .

With that the confirm method looks like the below:

public function confirm(): void
	$json = [];
	if ($this->config->get('config_cookie_id') && !isset($this->request->cookie['policy'])) {
		if (isset($this->request->get['agree'])) {
			$agree = (int) $this->request->get['agree'];
		} else {
			$agree = 0;
		$option = [
			'expires' => time() + 60 * 60 * 24 * 365,
			'path' => !empty($_SERVER['PHP_SELF']) ? '/' : '',
			'SameSite' => $this->config->get('session_samesite'),
		setcookie('policy', $agree, $option);
		$json['success'] = $this->language->get('text_success');
	$this->response->addHeader('Content-Type: application/json');

With these changes, the policy cookie is set and the policy cookie value is set to 1 or 0 as per the selection. You can see what cookie value is set by right-clicking on the page >> Inspect element (Chrome browser) >> Application tab >> Cookies tab on the left >> select the URL >> and you can see the policy value. Here in the example below the policy value is set to 1 as we clicked the accept cookie button.

Opencart cookie code changes to hide bar

In this way, you can manage the Cookies policies and GDPR policies on the Opencart websites of version 4 and for versions 3 and 2 you can use the Cookie module. Hope you liked this article, please subscribe to our YouTube Channel for Opencart video tutorials. You can also find us on Webocreation Twitter and Webocreation Facebook. Please let us know if you have any questions or concerns.

Previous articleLaravel Vs. Symfony: Checkout right PHP framework for your project
Next articleMake eCommerce Customers Feel Safe on the Website


Please enter your comment!
Please enter your name here