Site logo

[Resolved] Selectively display Add To Cart buttons

Home Forums Support [Resolved] Selectively display Add To Cart buttons

Home Forums Support Selectively display Add To Cart buttons

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2520653
    Brian

    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!

    #2520663
    Ying
    Staff
    Customer Support

    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 );
    	}
    });
    #2520675
    Brian

    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?

    #2520692
    Ying
    Staff
    Customer Support

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

    #2520699
    Brian

    Ah! Perfect, thank you SO much!!!

    #2520703
    Ying
    Staff
    Customer Support

    No Problem, glad to help 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.