WooCommerce Cart Hooks – WPDesk
The “Add your own sections to the cart page” in WPDesk’s WooCommerce Cart Hooks article is very helpful in learning how add_action hooks code works in functions.php file.
WPDesk’s “WooCommerce Empty Cart Hooks – Visual Guide” is also especially helpful.
add_action( 'woocommerce_before_cart_table', 'wpdesk_cart_welcome_to_cart_text' );
In the above code, WPDesk helps me see that the first part (woocommerce_before_cart_table) is the WooCommerce hook, and the second part (wpdesk_cart_welcome_to_cart_text) links to the HTML in the function part of the overall code that goes in the functions.php file.
Full code from WPDesk that goes in the functions.php file:
/* https://www.wpdesk.net/blog/woocommerce-cart-hooks/ */
add_action( 'woocommerce_before_cart_table', 'wpdesk_cart_welcome_to_cart_text' );
/**
* Add "Welcome to Cart" text to WooCommerce cart page
*
*/
function wpdesk_cart_welcome_to_cart_text() {
echo '<div class="woocommerce-info">Welcome to Cart!</div>';
}
Source: WooCommerce Cart Hooks – A Visual Guide with Examples