# fluent-cart/1.3.27/app/Hooks/Cart/CartLoader.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.3.27. 119 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.3.27/code/app/Hooks/Cart/CartLoader.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.3.27/raw/app/Hooks/Cart/CartLoader.php
- Modified: 2026-04-07T13:41:30+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.3.27/code/app/Hooks/Cart/CartLoader.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Hooks\Cart;

use FluentCart\Api\CurrencySettings;
use FluentCart\Api\Resource\FrontendResource\CartResource;
use FluentCart\Api\StoreSettings;
use FluentCart\App\App;
use FluentCart\App\Helpers\CartHelper;
use FluentCart\App\Helpers\Helper;
use FluentCart\App\Helpers\UtmHelper;
use FluentCart\App\Modules\Templating\AssetLoader;
use FluentCart\App\Vite;
use FluentCart\Framework\Support\Arr;
use FluentCart\App\Services\Renderer\CartRenderer;
use FluentCart\App\Services\Renderer\CartDrawerRenderer;

class CartLoader
{
    public function register()
    {
        add_action('wp_footer', [$this, 'init']);
    }

    public function init(): void
    {
        static $loadedOnce = false;

        if ($loadedOnce) {
            return;
        }

        // Stop rendering when loaded inside iframe (frontend iframe checkout, quick-view, etc.)
        if (
            isset($_SERVER['HTTP_SEC_FETCH_DEST']) &&
            $_SERVER['HTTP_SEC_FETCH_DEST'] === 'iframe'
        ) {
            return;
        }

        if (!AssetLoader::shouldLoadGlobalFrontendAssets()) {
            return;
        }

        $this->registerDependency();

        $loadedOnce = true;

        $enableNavFloatingButton = apply_filters('fluent_cart/buttons/enable_floating_cart_button', true, []);

        if (!$enableNavFloatingButton) {
            return;
        }

        if (self::shouldHideCartDrawer()) {
            return;
        }

        static::initCartDrawer();


    }

    public static function initCartDrawer(): void
    {
        static $loadedOnce = false;
        if ($loadedOnce) {
            return;
        }
        $loadedOnce = true;
        $cart = CartHelper::getCart(null, false);
        $itemCount = 0;

        if ($cart) {
            $itemCount = count($cart->cart_data ?? []);
        }

        $cartItems = Arr::get(CartResource::getStatus(), 'cart_data', []);

        if (empty($cartItems)) {
            return;
        }

        (new CartDrawerRenderer($cartItems, [
            'item_count' => $itemCount
        ]))->render();
    }

    public function registerDependency(): void
    {
        AssetLoader::loadCartAssets();
    }

    public function enqueueStyle()
    {
        $app = fluentCart();
        $slug = $app->config->get('app.slug');

        Vite::enqueueStyle(
            $slug . '-fluentcart-drawer',
            'public/cart-drawer/cart-drawer.scss',
        );
    }

    public static function shouldHideCartDrawer()
    {
        global $post;
        $currentPageId = $post->ID ?? null;
        $storeSettings = new StoreSettings();
        $cartPageId = $storeSettings->getCheckoutPageId();
        $receiptPageId = $storeSettings->getReceiptPageId();

        if (!CartHelper::doingInstantCheckout() && $cartPageId != $currentPageId && $receiptPageId != $currentPageId) {
            return false;
        }
        return true;
    }
}

```
