• Resolved dragondefeu76

    (@dragondefeu76)


    I’m facing a tricky problem: to display the “add to cart” button, I have to go through a piece of PHP code that allows to display the button under the product image, directly in the shop.
    BUT, I use a cache plugin, WP Rocket. And the cache does not work with PHP. There are documentaton on this.
    My question is : is there a way to have the “show to cart” button other than through the php code ?

    The code is (added via Snippet plugin)

    // Add "Add to Cart" buttons in Divi shop pages
    add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

    here there is a clear view of what happening when the shop page is not exlude from the cache https://www.loom.com/share/7a3d7c98b3ff4c30b678a1c5a0457aed?sid=7f9881cf-0f1e-41d1-9d51-d17959c8c101

    For now, I exclude the url of the WProcket’s cache. But if we reactivate it, after a while, the client will face the probleme which have been cast in the video : the product is not adding to the cart and the button keep spinning again and again.

    I figured out that the probleme should come from the PHP that is used to display the “add to cart ” button on shop page, which seems to generate a conflict with the cache. I tried several time and every time the cache is not cleared, the moment comes when the button is spinning around without actualize itself.

    May be I can share my cache’s setting here but I dont know how…

    thank you

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @dragondefeu76,

    I understand how frustrating this issue with your site and caching must be. To clarify, the Add to Cart button should appear on your Shop page by default, without requiring any additional code or modifications.

    However, depending on your theme or any customizations you’ve made, you might have needed to add custom code to enable it.

    Regarding caching, WP Rocket is a common cause of performance issues and conflicts. In many cases, loosening optimization and caching rules helps resolve the issue. Sometimes, excluding the Shop page from caching entirely is necessary.

    To be clear, this isn’t a PHP issue but rather a conflict between WP Rocket, your theme, or other plugins. I recommend:

    • Using less strict caching rules in WP Rocket
    • Trying an alternative caching plugin like WP Optimize
    • Excluding the Shop page from WP Rocket’s caching

    Since this issue isn’t directly related to WooCommerce, I’d suggest consulting an expert, as it falls outside our support scope.

    Thread Starter dragondefeu76

    (@dragondefeu76)

    ok, thank you. For now, I excluded the Shop page from WP Rocket’s caching.

    Zee

    (@doublezed2)

    Hello dragondefeu76,

    Thank you for your reply.

    For now, I excluded the Shop page from WP Rocket’s caching.

    Hopefully, this will resolve the issue.
    I suggest you monitor the site for a few days and let me know if the issue appears again.

    Have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘add to cart button / PHP / Cache’ is closed to new replies.