NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Woocommerce: Adding Custom Content in your Cart Page
Intermediate

---- Last modified : Oct 01 2022

Estimated reading time : 2 minutes, 27 seconds - 192 words

This tutorial will show you how to add custom content in your WooCommerce cart page with the help of specific hooks.

To do this custom coding, we strongly recommend using a WordPress child them and Woocommerce (obviously).

Make sure to not forget to enable the child them via Appearance –> Themes. It’s also vital to keep the parent theme.

Don’t forget to make a quick back up of your theme before making any changes.

List of custom hooks.

1 – woocommerce_before_cart
2 – woocommerce_before_cart_table
3 – woocommerce_before_cart_table
4 – woocommerce_cart_contents
5 – woocommerce_after_cart_contents
6 – woocommerce_after_cart_table
7 – woocommerce_before_cart_totals
8 – woocommerce_cart_totals_before_shipping
9 – woocommerce_before_shipping_calculator
10 – woocommerce_after_shipping_calculator
11 – woocommerce_cart_totals_after_shipping
12 – woocommerce_cart_totals_before_order_total
13 – woocommerce_cart_totals_after_order_total
14 – woocommerce_proceed_to_checkout
15 – woocommerce_after_cart_totals
16 – woocommerce_after_cart

By using the list of hooks above, here’s how you can add custom content to your cart page. For example, using the woocommerce_before_cart hook will display content just under the page’s title. Here’s how to insert it into your child theme.

It’s very important to change the naming of each function.

Here’s an example.

add_action('woocommerce_before_cart', 'nomdemafonction', 1);
function nomdemafonction() {
    echo 'Cher Clients'; 
	echo 'Vous pouvez obtenir la livraison gratuite à partir de 50 $ d’achat.'; 
}

La liste des hooks par default

// These are actions you can unhook/remove!
 
add_action( 'wp_loaded', array( WC_Cart, 'init' ) );
add_action( 'wp', array( WC_Cart, 'maybe_set_cart_cookies' ), 99 );
add_action( 'shutdown', array( WC_Cart, 'maybe_set_cart_cookies' ), 0 );
add_action( 'woocommerce_add_to_cart', array( WC_Cart, 'calculate_totals' ), 20, 0 );
add_action( 'woocommerce_applied_coupon', array( WC_Cart, 'calculate_totals' ), 20, 0 );
add_action( 'woocommerce_check_cart_items', array( WC_Cart, 'check_cart_items' ), 1 );
add_action( 'woocommerce_check_cart_items', array( WC_Cart, 'check_cart_coupons' ), 1 );
add_action( 'woocommerce_after_checkout_validation', array( WC_Cart, 'check_customer_coupons' ), 1 );
 
add_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
add_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 );
add_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>