woocommerce_loop_add_to_cart_link

WooCommerce applies this filter to add-to-cart link HTML in the classic product-loop template, allowing developers to modify catalog purchase links.

Quick Reference

TypeFilter hook
AreaProduct listings
Arguments$link (HTML string), $product (WC_Product), $args (array)
SourceWooCommerce code reference

How It Works

The template passes the finished add-to-cart link HTML, the current WC_Product object, and the arguments used to create the link. A filter callback must return HTML. Replacing the anchor entirely can remove quantity, accessibility, or AJAX-related attributes.

PHP Example

add_filter( 'woocommerce_loop_add_to_cart_link', function ( $link, $product, $args ) {
    return '<span class="catalog-cart-link">' . $link . '</span>';
}, 10, 3 );

This wraps the existing link for custom styling while retaining the original link's URL, text, classes, and attributes. Only return trusted HTML; escape any additional dynamic output.

Add the code to a site-specific plugin or a child theme's functions.php file, then test it on a staging site.

HoverCraft in Practice

HoverCraft styles the standard WooCommerce shop and category grids, including their purchase links. Keeping the existing link's classes and attributes when applying this filter helps preserve the expected appearance and behavior. See the WooCommerce Shop documentation for the theme's archive layout.

Common Pitfalls

Not every catalog button adds an item directly to the cart. Variable products may show a Select options link, and other product types can have different destinations or labels. Avoid replacing all links with a hardcoded add-to-cart URL. This is a filter, so the callback must return the modified HTML rather than echo it.

Compatibility

This hook is in the classic loop/add-to-cart.php template. Product blocks may generate add-to-cart controls through a different rendering path.