Site logo

Archived topic

Selectively display Add To Cart buttons

5 replies · Started by Brian on February 3, 2023

Viewing posts 1–6 of 6

I have "Display Add To Cart Buttons" turned off globally for WooCommerce shop pages as the vast majority of my shop I don't need to show the buttons.

However, I have a situation where I'll be loading some products onto a static page via a WC shortcode and am wondering if I can bring the add to cart buttons back just for that page/those products selectively?

Thanks for any insight!

Hi Brian,

You can use a filter like this, just need to replace the 4936 with the actual page id.

add_action('wp', function() {
	if (is_page ( 4936 ) ) {
		add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
	}
});

Awesome! That worked like a charm, thanks!

Out of curiosity, how would the snippet have to change if I wanted to add more than one page to the array?

Simple as?
if (is_page ( 4936 , 4937 , 4938 ) ) {

Or something more?

It would be if (is_page( array( 4936 , 4937, 4938 ) )) :)

Ah! Perfect, thank you SO much!!!

No Problem, glad to help :)

This archived topic is closed to new replies.