Fejlesztőknek
Kezdj bele
Témák/Theme SDK/Modules/price/Hooks

Hooks

Ez az oldal még csak angolul érhető el.

The hooks of @poltura/theme-sdk/price.

Ezen az oldalon
import { … } from '@poltura/theme-sdk/price';

usePrice

The amounts behind a price, for code that must compute with them.

usePrice(price: PriceView | null): ResolvedPrice | null

Parameters

  • price: PriceView | null: The price of a product, variant or card.

Returns: The resolved amounts, or null on pages with live prices (islands) and for hidden prices.

Example

import { usePrice } from '@poltura/theme-sdk/price';
import type { PriceView } from '@poltura/theme-sdk/price';

export function OnSale({ price }: { price: PriceView }) {
  const resolved = usePrice(price);
  return resolved?.compareAt ? <span>Sale</span> : null;
}

usePriceAccess

Whether the visitor may see prices, on which tax basis, and what unlocks them when hidden.

usePriceAccess(): PriceAccess

Returns: The visitor's price access.

Example

import type { ReactNode } from 'react';
import { PriceGate, usePriceAccess } from '@poltura/theme-sdk/price';

export function PricesOrGate({ children }: { children: ReactNode }) {
  const access = usePriceAccess();
  return access.visible ? <>{children}</> : <PriceGate />;
}
Utoljára frissítve