Additional content under the “Add to cart” button on the product page in the categories indicated

To add content under the “Add to cart” button on the product page in the categories indicated, add the following code to the file functions.php in the theme directory. You shold modify this code to set desired categories – $my_categories variable, line 3. And the content to be displayed – line 14.

add_action( 'woocommerce_after_add_to_cart_button', 'studiowp_woocommerce_after_add_to_cart_button' );
function studiowp_woocommerce_after_add_to_cart_button() {
	global $product;
	$my_categories = array( 15, 16 );
	$is_my_category = false;
	$product_categories = $product->get_category_ids();
	foreach ( $my_categories as $my_category ) {
		if ( in_array( $my_category, $product_categories ) ) {
			$is_my_category = true;
		}
	}
	if ( $is_my_category ) {
		?>
		
My content

View the code on Gist.

If you do not use the child theme, remember that changes made to the functions.php file will be overwritten when the theme is updated.

While copying code to functions.php file it is not nessesary to copy <?php opening tag.

About grola

Passionate about Wordpress and WooCommerce for many years. Author of plugins and short snippets improving Wordpress and WooCommerce.

View all posts by grola →