Add Custom Content Above Cart Items in WooCommerce

In WooCommerce, you might want to display additional information or promotional messages above the cart items on the cart page. This can be achieved easily using WooCommerce hooks. In this post, we’ll learn how to add custom content above cart items in WooCommerce.

/**
* Snippet Name:  Adding Custom Content Above Cart Items
* Snippet Author:  wpsnippets.dev
*/

// Add custom content above cart items
function wps_custom_content_above_cart_items() {
    echo '<div class="wps_custom-content">';
    echo '<p>This is a custom message displayed above cart items.</p>';
    echo '</div>';
}
add_action( 'woocommerce_before_cart_table', 'wps_custom_content_above_cart_items' );

Code Explanation

  • The code utilizes the woocommerce_before_cart_table hook to add custom content above the cart items.
  • The wps_custom_content_above_cart_items function displays the custom content within an <div> element with the class custom-content. You can modify the content inside the <p> tag to display any message or information you desire.

Leave a Comment

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

Scroll to Top