Skip to main content

Product

Display WooCommerce product data in your templates. Requires WooCommerce to be active.

The Product provider inherits all Post fields — title, link, excerpt, thumbnail, dates, author, custom fields, and everything else. Only product-specific fields are listed here.

In the WC admin UI, post fields are renamed: content is the product Description, excerpt is the product Short Description.

Requires WooCommerce

The Product provider only activates when WooCommerce is active. If WooCommerce is deactivated, product fields return empty values. Post fields (title, link, etc.) still work because products are a custom post type.

How It Works​

When you loop over products with post_type: 'product', use any variable name — Unblock detects the post type from each WP_Post and exposes the matching product fields automatically:

{% for product in get_posts({post_type: 'product', posts_per_page: 6}) %}
{{ product.title }}
{{ product.price | currency }}
{% endfor %}

You still have access to every Post field — product.title, product.thumbnail, product.excerpt, product.link, etc.

All Fields​

FieldArgumentsReturnsDescription
sku—stringProduct SKU
product_type—stringsimple, variable, grouped, or external
category—Term | nullPrimary product category (first product_cat term, comparable to a string)
categories—Term[]Product categories (product_cat taxonomy)
tags—Term[]Product tags (product_tag taxonomy)
attributes—arrayAll product attributes (normalized: name, label, value, taxonomy, visible, variation)
attributenamestringA single attribute formatted as a comma-separated string
variationslimitProduct[]Purchasable variations (variable products only)
variation_attributes—arrayVariation's attribute selection (variations only, {slug: value})
price—stringEffective price (sale price if on sale, regular otherwise)
regular_price—stringRegular price
sale_price—stringSale price (empty if not on sale)
is_on_sale—boolWhether the product is currently on sale
discount_percent—float | nullDiscount percentage (null if not on sale)
price_html—stringFull WooCommerce price HTML (includes <del> for sale)
date_on_sale_fromformatstring | nullSale start date (null if not scheduled)
date_on_sale_toformatstring | nullSale end date (null if not scheduled)
stock_quantity—int | nullStock quantity (null if not tracked)
stock_status—stringinstock, outofstock, or onbackorder
is_in_stock—boolWhether the product is in stock
is_on_backorder—boolWhether currently on backorder
is_virtual—boolWhether virtual (no shipping)
is_downloadable—boolWhether downloadable
is_featured—boolWhether marked as featured
is_purchasable—boolWhether the product can be added to the cart
min_purchase_quantity—intMinimum purchase quantity
max_purchase_quantity—intMaximum purchase quantity (-1 if unlimited)
weight—stringProduct weight
length—stringProduct length
width—stringProduct width
height—stringProduct height
dimensions—stringFormatted dimensions (L × W × H unit)
shipping_class—stringShipping class slug
product_gallerylimitImage[]Gallery images (each is a full Image object)
upsellslimitProduct[]Upsell products (each is a full Product)
cross_sellslimitProduct[]Cross-sell products (each is a full Product)
relatedlimit, excludeProduct[]Related products auto-computed by WooCommerce. Default limit 5. Accepts positional args or a config object ({limit, exclude}).
total_sales—intTotal units sold
average_rating—stringAverage rating (0–5, '0' by default)
review_count—intNumber of reviews
add_to_cart_url—stringAdd to cart URL
add_to_cart_text—stringAdd to cart button text

The currency filter​

Formats a number as WooCommerce currency using wc_price(). Uses your store's configured currency symbol, thousand separator, and decimal settings.

{{ product.price | currency }}            <!-- $29.99 -->
{{ product.regular_price | currency }} <!-- $39.99 -->

Without currency, you get the raw number. With it, you get the formatted output matching your WooCommerce settings.

Common Patterns​

Sale badge​

{% if product.is_on_sale %}
<s>{{ product.regular_price | currency }}</s> -{{ product.discount_percent }}%
{% endif %}
{{ product.price | currency }}

Stock status​

{% if product.is_in_stock %}In stock{% endif %}
{% if not product.is_in_stock %}Out of stock{% endif %}
{% for image in product.product_gallery %}
{{ image.src('thumbnail') }}
{{ image.alt }}
{% endfor %}

Upsells section​

{% for upsell in product.upsells(4) %}
{{ upsell.thumbnail.src('medium') }}
{{ upsell.title }}
{{ upsell.price | currency }}
{% endfor %}
Common mistake

Don't forget the currency filter when displaying prices. Without it, product.price returns a raw number like 29.99 — no currency symbol, no formatting. Always use {{ product.price | currency }} to match your WooCommerce store settings.

Next Steps​

  • Post provider — All inherited fields available on products
  • Image provider — Working with gallery images and thumbnails
  • Loop — Query and loop over products with get_posts