Customize the WooCommerce cart page with hooks

Customizing the WooCommerce basket page with hooks

To add text, an image or a whole block to the WooCommerce cart page, you use hooks: locations provided by WooCommerce where you attach your own content with a few lines of PHP. Combined with an Elementor template, they let you insert a real layout, exactly where you want it. One condition: use the classic cart.

In short

  • A hook is a named location where you can add content without editing WooCommerce.
  • The cart page has about twenty of them: above the table, below the totals, near the checkout button…
  • A shortcode goes through do_shortcode() to display an Elementor template.
  • Hooks work with the classic cart; the Cart block, the default on recent shops, does not use them.

What is a hook?

A hook is an attachment point provided by the developer of a plugin, here WooCommerce. It lets you add content or change a behavior at a precise moment, without touching the plugin’s files. So your code survives updates.

Classic cart or Cart block?

Since WooCommerce 8.3, new shops use the Cart block by default. It does not fire these hooks: you customize it in the block editor. The hooks apply to the classic cart, the one from the [woocommerce_cart] shortcode, still maintained by WooCommerce. If your cart page contains the block, replace it with a Shortcode block containing [woocommerce_cart].

The cart page hooks

In display order:

  • woocommerce_before_cart
  • woocommerce_before_cart_table
  • woocommerce_before_cart_contents
  • woocommerce_cart_contents
  • woocommerce_cart_coupon
  • woocommerce_after_cart_contents
  • woocommerce_after_cart_table
  • woocommerce_cart_collaterals
  • woocommerce_before_cart_totals
  • woocommerce_cart_totals_before_shipping
  • woocommerce_before_shipping_calculator
  • woocommerce_after_shipping_calculator
  • woocommerce_cart_totals_after_shipping
  • woocommerce_cart_totals_before_order_total
  • woocommerce_cart_totals_after_order_total
  • woocommerce_proceed_to_checkout
  • woocommerce_after_cart_totals
  • woocommerce_after_cart

Example 1: add a simple line of text

To show text above the cart total, use woocommerce_before_cart_totals. Add this code to the functions.php file of your child theme (otherwise it will be overwritten at the next theme update), or in the Code Snippets plugin:

add_action( 'woocommerce_before_cart_totals', 'wycan_texte_avant_total_panier' );
function wycan_texte_avant_total_panier() {
    echo '<p>Free shipping on orders of €60 or more.</p>';
}

The first line names the hook; the text in quotes is what appears on screen. The result:

WooCommerce basket page with a custom text shown just above the Basket totals block
The text appears just above the cart total.

Example 2: insert an Elementor template

A line of text is good. Two columns with an image and a button are better. With Elementor Pro, every template in your library has a shortcode in the form .

1. Create the template

In Templates, then Add New, create a template of the Section (or Container) type, build the content you want and publish it. In the list of templates, copy its shortcode from the right-hand column.

2. Insert it with a hook

To place the template between the product table and the total, use woocommerce_after_cart_table. A shortcode is not interpreted on its own in PHP: you have to pass it to do_shortcode().

add_action( 'woocommerce_after_cart_table', 'wycan_modele_apres_tableau_panier' );
function wycan_modele_apres_tableau_panier() {
    echo do_shortcode( '[elementor-template id="701"]' );
}

Replace 701 with the ID of your template, save, then reload the cart page.

WooCommerce basket page with an Elementor promotional block, a T-shirt image, a heading and a button, inserted between the product table and the total
An Elementor template inserted between the product table and the total.

Without Elementor Pro

The principle is the same with any shortcode: a form’s, a reusable block’s or one from your theme’s library. The OceanWP theme, for example, provides a shortcode for each item in its library.

Several additions on the same page

You can attach as many pieces of content as you like, on different hooks or on the same one. Just one rule: each function needs a unique name. Two functions with the same name cause a fatal error and take the site down. Prefix them, as here with wycan_.

Want a cart that encourages people to buy, with free shipping, complementary products and reassurance? We design custom WooCommerce shops, or let’s talk about your shop.

Contents
Read next

More articles that may help you

Illustration au trait : un casque audio, une onde sonore, un stockage de fichiers et le symbole d’un flux RSS

Self-hosted podcast: moving a podcast to WordPress and Cloudflare R2

Read the article →
Illustration au trait : une patinoire vue de dessus, des sapins et un écran d’état avec deux pastilles

Ice rink and skating trail: a municipality’s custom WordPress plugin

Read the article →
WooCommerce e-invoicing: how to make your shop compliant

WooCommerce e-invoicing: how to bring your shop into compliance

Read the article →

A project, a question?

Free quote · Refundable deposit · Balance only if satisfied · No commitment