Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Disable Woocommerce cart fragments for homepage via .htaccess
# By creating empty response
# Please replace yoursite.com
# Disable only on homepage
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https://yoursite.com/$ [NC]
RewriteCond %{QUERY_STRING} ^wc-ajax=get_refreshed_fragments$
RewriteRule ^(.*)$ $1 [R=204,L]
# Disable everywhere
RewriteEngine On
RewriteCond %{QUERY_STRING} ^wc-ajax=get_refreshed_fragments$
RewriteRule ^(.*)$ $1 [R=204,L]
@guikare

This comment has been minimized.

Copy link

guikare commented Nov 22, 2018

doesnt work!

@cultd3ad

This comment has been minimized.

Copy link

cultd3ad commented Dec 3, 2018

for me works on Apache 2.4 with nginx Proxy

@virgilshelton

This comment has been minimized.

Copy link

virgilshelton commented Dec 5, 2018

Works, thanks on Apache 2!

@lukapaunovic

This comment has been minimized.

Copy link
Owner Author

lukapaunovic commented Jan 2, 2019

@guikare

doesnt work!

It doesn't work with some configurations, so here's an alternative that does.
It requires creating a blank 404.php file from which we'll get a blank response

# BEGIN Disable cart fragments
RewriteEngine On
# Uncomment rule bellow and update with your site url if you want to disable only for homepage
#RewriteCond %{HTTP_REFERER} ^https://yoursite.com/$ [NC]
RewriteCond %{QUERY_STRING} ^wc-ajax=get_refreshed_fragments$
RewriteRule ^(.*)$ /404.php [NC,L]
# END Disable cart fragments
@jayeq

This comment has been minimized.

Copy link

jayeq commented Jan 28, 2019

Didn't work for me (tried disabling everywhere) but the alternative seems better for me. It does cause a 500 error based on the waterfall but at least it's quick vs. the 1s+ the call was taking before. Thanks!

As for that internal error, it makes me believe something's not right since it should be finding the 404.php file I created, no??? Any ideas on how to fix that? Sometimes, it's taking >500ms to return the 500 error...

@lukapaunovic

This comment has been minimized.

Copy link
Owner Author

lukapaunovic commented Feb 2, 2019

@jayeq, if you are using the method which uses 404.php file then you need to create that file, of course.

The content of the 404.php file should be:

<?php
http_response_code(204);
die();

Then in waterfall u should see 204 response instead of 500 error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.