Disable WooCommerce Cart Fragments Scripts with WPMasterToolKit
WooCommerce, one of the most popular e-commerce solutions for WordPress, uses a script called Cart Fragments to update the contents of the shopping cart on the front-end in real time via AJAX. While this functionality is useful for some sites, it may be superfluous for others, particularly those that don't use dynamic basket updating. In addition, this script may slow down the site by adding unnecessary AJAX requests. The module Disable Cart Fragments Scripts from WPMasterToolKit has been designed to solve this problem, disabling this script and optimizing your site's performance.
Why disable Cart Fragments scripts?
Here are the main reasons why you might want to disable this script:
- Performance enhancement AJAX requests generated by
wc-cart-fragments
can slow down initial page loading, especially on sites with a lot of traffic. - Simplification for sites without a dynamic shopping cart If your site doesn't require dynamic updating of cart contents (for example, if you redirect your customers directly to the cart page after adding a product), these scripts become unnecessary.
- Reduce unnecessary requests By deactivating
wc-cart-fragments
In this way, you eliminate AJAX calls that consume server resources.
How the Disable Cart Fragments Scripts module works
The module Disable Cart Fragments Scripts disables WooCommerce scripts related to the dynamic shopping cart, and configures your site to avoid related functionality, such as AJAX addition to the shopping cart. Here's what it does in detail:
Disabling scripts wc-cart-fragments
The module uses the wp_enqueue_scripts
to unregister the script wc-cart-fragments
preventing it from being loaded on the front-end.
Modifying WooCommerce settings
When the module is activated, the WooCommerce settings are automatically adjusted:
- Redirect after adding to cart Enable the option to redirect to the shopping cart page after adding a product.
- Disable AJAX addition to basket Disables AJAX-based shopping cart functionality, eliminating dependency on dynamic scripting.
WooCommerce administration
The module also includes a specific script for the WooCommerce settings page to ensure that add-to-cart behaviors are correctly configured in the administration interface.
Restore settings on deactivation
When the module is deactivated, it restores WooCommerce's default settings, reactivating the AJAX shopping cart functionality if necessary.
How to use this module
- Installation : Install and activate the plugin WPMasterToolKit on your WordPress site.
- Module activation Go to the list of modules and activate "Disable Cart Fragments Scripts".
- Automatic configuration Once activated, the module disables scripts
wc-cart-fragments
and adjusts WooCommerce settings without further intervention.
Our technical choices for this module
Using native hooks
The module uses the wp_enqueue_scripts
to unregister dynamic scripts. This method ensures that the script is removed cleanly, with no risk of impacting other WooCommerce features.
Parameter management via activation and deactivation
By modifying the WooCommerce options on activation and deactivation, the module ensures compatibility with the default WooCommerce behavior.
Conditional loading
The module does not load any unnecessary code, in line with the WPMasterToolKit philosophy of "one module activated = one module loaded". Modifications apply only when the module is active.
Conclusion
The module Disable Cart Fragments Scripts from WPMasterToolKit is an ideal solution for WooCommerce site owners looking to improve performance by removing unnecessary dynamic shopping cart scripts. Simple to use and fully automated, it guarantees a faster site without compromising user experience. Try it today to optimize your online store!