WooCommerce
Design your shop, cart, checkout and account screens as CanAI templates, with cart and customer data ready to use in Twig.
What it is and when to use it
When WooCommerce is active, CanAI can take over its storefront screens. You create a template, give it a template type, and CanAI uses it automatically on the matching screen. Nothing changes until you create a template of that type.
| Group | Types |
|---|---|
| Storefront | shop, product, product-category, product-loop |
| Purchase | cart, checkout, order-received |
| Account | my-account, plus the endpoints orders, view-order, downloads, edit-account, edit-address, payment-methods, lost-password |
| Other endpoints | order-pay, add-payment-method |
Pair these with a layout template so the header and footer stay shared across shop screens. Products can also carry their own CanAI markup.
Other plugins can register extra page types with the wpcanai_template_types filter; built-in WooCommerce types win on a conflict.
What your Twig can use
Templates get these variables when WooCommerce is present:
cart:item_count,is_empty,subtotal_html,total_html,needs_shipping,discount_total_html,coupons, anditems(each withquantity,product.name,product.url,product.image,variation_label,line_total_html,remove_url)customer: billing name, city, postcode, country, state, email and phonepayment_gatewaysandshipping_methodsproducton a single product,orderon the order-received (thank-you) page- On
shopandproduct-category:products(with featured image),pagination,current_category/term, andattribute_filtersfor layered navigation
Context is read-only. CanAI never changes the cart or customer while building a page; changes go through WooCommerce's own forms.
Helper functions include wc_price, wc_get_product, wc_shop_url, wc_get_cart_url, wc_get_checkout_url, wc_pagination, wc_print_notices, wc_form_field, wc_add_to_cart_form, wc_cart_totals, wc_checkout_form, wc_cart_block and wc_checkout_block.
Example: a cart summary
{% if cart.is_empty %}
<p>Your cart is empty. <a href="{{ wc_shop_url() }}">Keep shopping</a></p>
{% else %}
<ul>
{% for item in cart.items %}
<li>{{ item.quantity }} x {{ item.product.name }} {{ item.line_total_html|raw }}</li>
{% endfor %}
</ul>
<p>Total: {{ cart.total_html|raw }}</p>
<a href="{{ wc_get_checkout_url() }}">Checkout</a>
{% endif %}
Letting WooCommerce extensions show up
Wishlist buttons, review widgets and similar add-ons attach to WooCommerce display hooks. Fire one from your template with wc_hook:
{{ wc_hook('woocommerce_single_product_summary') }}
Only an allowlist of hooks fires; anything else returns nothing. The defaults cover single product (woocommerce_before_single_product, ..._before_single_product_summary, ..._single_product_summary, ..._after_single_product_summary, ..._after_single_product, woocommerce_product_meta_start, woocommerce_product_meta_end, woocommerce_share), the shop loop (woocommerce_before_shop_loop, woocommerce_after_shop_loop, woocommerce_shop_loop) and cart/checkout (woocommerce_before_cart, woocommerce_after_cart, woocommerce_checkout_before_customer_details, woocommerce_review_order_before_payment). Developers can add more with the wpcanai_wc_hook_allowlist filter.
For agents
When WooCommerce is active, wpcanai/get-wc-page-ids returns the shop, cart, checkout and account page IDs, and wpcanai/get-wc-css-reference returns the styling rules and template paths for WooCommerce's own markup, so an agent can style wc_* helper output correctly. Both tools register only on sites that have WooCommerce.
Orders and HPOS
CanAI is safe with WooCommerce High-Performance Order Storage. Its only touch of orders is reading one through wc_get_order(); it never queries order posts or legacy order meta directly.
If something looks wrong
- A shop screen ignores your template: check the template has the right type and is published. Look at CanAI -> Tools -> Diagnostics for the WooCommerce integration.
wc_hookprints nothing: the hook is not on the allowlist, or you are on a screen where it does not apply (single-product hooks need a product).- Checkout looks unstyled: use
wc_checkout_form()orwc_checkout_block()rather than rebuilding the form, and ask the agent forwpcanai/get-wc-css-reference. - Template warnings: run the content scan; render warnings are also listed in Diagnostics under the render group.