# fluent-cart/1.5.2/app/Hooks/Handlers/CartCookieHandler.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.5.2. 41 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.5.2/code/app/Hooks/Handlers/CartCookieHandler.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.5.2/raw/app/Hooks/Handlers/CartCookieHandler.php
- Modified: 2025-10-14T16:36:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.5.2/code/app/Hooks/Handlers/CartCookieHandler.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Hooks\Handlers;

use FluentCart\Api\Hasher\Hash;
use FluentCart\App\App;

class CartCookieHandler
{
    public static function handle()
    {
        $app = App::getInstance();
        //Set up the cookie before any header info is sent to a client
        $app->addAction('init', function () use ($app) {

            if (App::doingRestRequest()) {
                return;
            }

            $cartCookie = \FluentCart\Api\Cookie\Cookie::getCartHash();
            if (!$cartCookie) {
                \FluentCart\Api\Cookie\Cookie::setCartHash(
                    md5(time() . wp_generate_uuid4())
                );
            }
        });


        add_filter('rest_request_before_callbacks', function ($response, $handler, $request) {
            // Only set cookie if not already present
            $cartCookie = \FluentCart\Api\Cookie\Cookie::getCartHash();
            if (!$cartCookie) {
                \FluentCart\Api\Cookie\Cookie::setCartHash(
                    md5(time() . wp_generate_uuid4())
                );
            }
            // Return null to let the normal REST flow continue
            return null;
        }, 10, 3);
    }
}
```
