How to Hide Free Shipping for Specific Coupons in WooCommerce
Автор: vlogize
Загружено: 2025-09-08
Просмотров: 2
Learn how to easily `disable free shipping` in WooCommerce when certain coupons are applied, enhancing your store's functionality and user experience.
---
This video is based on the question https://stackoverflow.com/q/63398076/ asked by the user 'user3037553' ( https://stackoverflow.com/u/3037553/ ) and on the answer https://stackoverflow.com/a/63401899/ provided by the user 'LoicTheAztec' ( https://stackoverflow.com/u/3730754/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Hide free shipping when specific coupons are applied in Woocommerce
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
How to Hide Free Shipping for Specific Coupons in WooCommerce
Offering free shipping can be a great way to incentivize purchases in your WooCommerce store. However, there might be instances where you want to avoid offering free shipping in conjunction with certain specific coupons. If you're facing this challenge, you're not alone! This guide will help you disable free shipping when a specific coupon is applied to the cart.
Understanding the Problem
The goal is to disable the free shipping option for specific coupons. This requirement often arises when you want to maintain profit margins or when certain discounts might make the offer less sustainable. For example, a coupon giving a huge discount may not warrant additional free shipping.
The Solution to Your Problem
Using Code to Customize Shipping Options
To achieve the desired functionality, we can leverage hooks available in WooCommerce. Here's how you can implement this solution:
Accessing Your Theme's Functions File
You will need to add the code snippet to the functions.php file of your active WordPress theme (preferably a child theme for customization).
You can access the functions.php file by going to your WordPress admin, then navigate to Appearance Theme Editor.
Adding the Correct Code Snippet
Use the following code to target specific coupons and remove free shipping options accordingly:
[[See Video to Reveal this Text or Code Snippet]]
Important Notes about the Code:
Customize coupons: Replace "544" in the $targeted_coupons array with your desired coupon codes.
Understanding the Code:
The code utilizes the woocommerce_package_rates filter to manipulate the shipping rates based on the applied coupons.
It checks for the presence of the specified coupon and removes any free shipping methods available.
Refreshing the Shipping Cache
After making changes to the functions.php file, it is crucial to refresh the shipping caches. Follow these simple steps:
Save the code in your functions.php file.
Navigate to the Shipping Zone settings in WooCommerce.
Disable any shipping method, save changes, then re-enable it and save again.
You are done! Test the checkout process with the coupon applied to ensure the free shipping option is indeed hidden.
Conclusion
Disabling free shipping for specific coupons in WooCommerce is straightforward with the right approach. By understanding the hooks available and how to manipulate shipping rates based on applied coupons, you can tailor your checkout experience to fit your business needs.
Feel free to reach out if you have any questions or need further assistance in customizing your WooCommerce setup!
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: