Menu-new
Close
< All Topics
Print

How to add text under add to cart

Intro:

To add custom text under the “Add to cart” button in WooCommerce (on the single product page), you can use a small code snippet in your child theme’s functions.php file or a custom plugin.

The code:

				
					add_action('woocommerce_after_add_to_cart_button', 'custom_text_by_category');

function custom_text_by_category() {
    global $product;

    if (has_term('category-slug-one', 'product_cat', $product->get_id())) {
        echo '<p class="custom-cart-text">
            Ships within 24 hours – <a href="/shipping-info" target="_blank">See shipping info</a>
        </p>';
    }
    elseif (has_term('category-slug-two', 'product_cat', $product->get_id())) {
        echo '<p class="custom-cart-text">
            Limited stock – <a href="/stock-details" target="_blank">More about availability</a>
        </p>';
    }
}

				
			

Replace:

● /shipping-info → with the URL to your shipping info page.

● /stock-details → with the URL to your availability/stock details page.

You can use full URLs (https://yourdomain.com/page) or relative (/page).

Example CSS:

				
					custom-cart-text {
	font-size: 15px;
	color: #444;
	margin-top: 60px;
	margin-bottom: 20px;
	border: dashed 3px #77a464;
	border-radius: 10px;
	padding: 10px;
}
.custom-cart-text a {
	font-weight: 700;
}
.custom-cart-text a:hover {
	font-weight: 700;
	color: #000000;
}

				
			
Table of Contents