Website Building » WooCommerce » How Do I Create a Custom Cart Page in WooCommerce?

How Do I Create a Custom Cart Page in WooCommerce?

Last updated on January 19, 2023 @ 2:58 pm

If you’re running a WooCommerce store, you might want to customize the look of the cart page to match the rest of your site. Luckily, it’s relatively easy to do this with a few lines of code.

First, you’ll need to create a new file called “cart.php” in your child theme’s folder. You can do this using a text editor like Notepad++ or Sublime Text.

Next, copy and paste the following code into your newly created “cart.php” file:

<?php
/**
 * The template for displaying the cart page.
 *
 * @package WooCommerce
 * @since 1.6
 */
 
global $woocommerce;
 
$woocommerce->show_messages(); ?>
 
<form action="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>" method="post">

<?php do_action( 'woocommerce_before_cart_table' ); ?>

<table class="shop_table cart" cellspacing="0">

<thead>

<tr>

<th class="product-remove"> </th>

<th class="product-thumbnail"> </th>

<th class="product-name"><?php _e('Product', 'woocommerce'); ?></th>

<th class="product-price"><?php _e('Price', 'woocommerce'); ?></th>

<th class="product-quantity"><?php _e('Quantity', 'woocommerce'); ?></th>

<th class="product-subtotal"><?php _e('Total', 'woocommerce'); ?></th>

</tr>

</thead>

<tbody>

<?php do_action( 'woocommerce_before_cart_contents' ); ?>

<?php foreach ( $woocommerce->cart->get_cart() as $cart_item ) : $_product = $cart_item['data']; if ( ! $_product->exists() || $cart_item['quantity'] == 0 ) continue; // Skip if product no longer exists or has been removed from cart ?>
PRO TIP: If you are not a developer or comfortable with code, do not attempt to customize your WooCommerce cart page. You can break your site if you make a mistake.
Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.