UseProductPriceContext hook
const productPriceContext = useProductPriceContext();
This hook can be used in content element on product details page. Content elements can access price information for product displayed on the page.
The useProductPriceContext hook provides info about the product price for content elements.
This hook returns the object with data or null if it's not being used on the product details page, or price information is not loaded yet.
The data contains following properties:
| Property | Type | Description |
|---|---|---|
| price | number | null | Product price. Can be null in case it is not allowed to see prices for current user or product was not found. |
| listPrice | number | null | Product list price. Can be null in case it is not allowed to see prices for current user or product was not found. |
| pricePerBaseUom | number | null | undefined | Price per base unit of measure. Will be null in case current unit of measure is equals to base unit of measure or price per base unit of measure is hidden. Can be undefined if current user cannot view unit of measure. |
Example:
const productPriceContext = useProductPriceContext();
if (!productPriceContext)
return null;
const {
price,
listPrice,
pricePerBaseUom,
} = productPriceContext;
Related hooks
| Hook | Purpose |
|---|---|
| useProductContext | Read product data, including the current variantId |
| useProductVariantContext | Programmatically change the selected product variant |
| useProductStockContext | Read stock for the currently selected variant |