How to check cookie restriction mode enabled programmatically Magento 2?

You can check the cookie restriction mode value enabled or not for the current store using Magento 2.

Cookie Restriction mode XML config path is ‘web/cookie/cookie_restriction’ and you can check the value for the specified store using Helper class.

Magento\Cookie\Helper\Cookie class contains public function isCookieRestrictionModeEnabled() to verify Mode is enabled for the current store.

<?php
namespace Jesadiya\CookieMode\Model;

use Magento\Cookie\Helper\Cookie;

class CookieRestriction
{
    /**
     * @var Cookie
     */
    private $cookieHelper;

    public function __construct(
        Cookie $cookieHelper
    ) {
        $this->cookieHelper = $cookieHelper;
    }

    /**
     * Return cookie restriction mode value.
     *
     * @return bool
     */
    public function isCookieRestrictionModeEnabled(): bool
    {
        return $this->cookieHelper->isCookieRestrictionModeEnabled();
    }
}

You can verify the cookie restriction setting using the given code snippet.

You can also check the value from the Magento Admin panel also from the Settings -> Configuration scope.