Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Set All Shipping Methods’ Cost to Zero for a Free Shipping Coupon in WooCommerce?

WooCommerce built-in functionalities help you to smartly set up shipping methods and allow free shipping to all products. But when your online store is jumping into clearance sale of certain products you may provide coupons combined with free shipping. In this case, you need to explore smart choices to change the rates of other shipping methods. 

This post helps you to set all shipping methods costs to zero for a free shipping coupon in WooCommerce.

Where to Add Custom Code in WooCommerce?

It is advisable to add the code snippets to the functions.php file of your child theme. Access the file directly from Appearance->Theme File Editor->Locating the child theme’s functions.php from the right sidebar. You can also access it from your theme’s directory file. Insert the following code snippet in functions.php. The alternative & easy option is to install & activate the Code Snippets plugin. You can then add the code as a new snippet via the plugin.

Avoiding Online Scams: Casinozoid’s Guide to Safe Gambling

As the world of online gambling continues to expand, so too does the risk of falling victim to online scams and fraudulent activities. In today’s digital age, ensuring safe and secure online gambling practices is more crucial than ever. Casinozoid’s Guide to Safe Gambling is here to shed light on the common pitfalls and dangers of online casinos, offering invaluable insights on how to protect yourself and your hard-earned money while enjoying the thrill of online gaming.

In this comprehensive guide, we will delve into the various types of online scams that target unsuspecting players, providing practical tips and strategies to help you navigate the virtual gambling landscape with confidence. From identifying red flags to understanding the importance of reputable online casinos, Casinozoid’s expert advice will empower you to make informed decisions and safeguard your online gaming experience. Join us on this journey as we uncover the secrets to avoiding online scams and embracing a safer, more enjoyable online gambling adventure.

Identifying Common Online Scams in the Gambling Industry

When it comes to online gambling, staying safe and avoiding scams is paramount. At Casinozoid, we understand the importance of protecting your personal and financial information while enjoying your favorite casino games. One of the key tips we recommend is to always choose reputable and licensed online casinos. Look for certifications from trusted regulatory bodies such as the UK Gambling Commission or the Malta Gaming Authority.

Another essential practice is to carefully review the terms and conditions of any online casino before signing up or making a deposit. Watch out for vague or confusing terms, unrealistic bonuses, or withdrawal restrictions that could signal a potential scam. Additionally, be cautious of unsolicited emails or messages offering exclusive deals or promotions, as these are often tactics used by scammers to lure unsuspecting players.

Lastly, never share sensitive information such as your password, banking details, or identification documents with anyone claiming to represent an online casino. Legitimate operators will never ask for this information via email or chat. By following these guidelines and staying vigilant, you can enjoy a safe and secure online gambling experience at Casinozoid.

Best Practices for Safeguarding Your Personal and Financial Information

When it comes to online gambling, staying safe and secure is of utmost importance. Casinozoid’s comprehensive guide to safe gambling is designed to help players navigate the digital casino landscape with confidence. By following our expert tips and advice, you can protect yourself from falling victim to online scams and ensure a positive gaming experience.

One of the key aspects of safe online gambling is choosing reputable and licensed online casinos. Casinozoid recommends players to only play on platforms that are regulated by recognized authorities and have a proven track record of fair play. By doing so, you can avoid potential scams and fraudulent activities that may put your personal and financial information at risk.

Additionally, Casinozoid emphasizes the importance of practicing responsible gaming habits. Setting limits on your deposits, wagering, and time spent playing can help you avoid getting caught up in risky behavior. By following the guidelines laid out in Casinozoid’s guide to safe gambling, you can enjoy the thrill of online gaming while safeguarding yourself against potential online scams.

Ensuring the Legitimacy of Online Casinos: Tips for Responsible Gambling

When it comes to online gambling, staying safe and avoiding scams is paramount. Casinozoid’s Guide to Safe Gambling provides valuable tips to help players navigate the online casino world securely. First and foremost, always choose reputable and licensed online casinos. These casinos operate under strict regulations, ensuring fair play and secure transactions.

Another crucial aspect highlighted in Casinozoid’s guide is to be wary of unsolicited emails or messages promising huge winnings or exclusive offers. Scammers often use these tactics to lure unsuspecting players into fraudulent schemes. It’s important to verify the legitimacy of any online casino before providing personal or financial information.

Furthermore, Casinozoid emphasizes the importance of setting limits and sticking to a budget while gambling online. Responsible gaming practices can help players avoid falling into the traps of online scams and ensure an enjoyable and safe gambling experience. By following these guidelines outlined by Casinozoid, players can protect themselves from potential scams and focus on the thrill of online gaming responsibly.

Reporting and Responding to Suspicious Activities in Online Gambling Platforms

When it comes to online gambling, staying safe and avoiding scams is crucial for an enjoyable experience. At Casinozoid, we understand the importance of protecting players from fraudulent activities. One of the first steps in safe gambling is to choose reputable online casinos. Look for platforms with valid licenses and positive reviews from other players. Avoid casinos that have a history of withholding winnings or engaging in unethical practices.

Another essential tip is to be cautious of offers that seem too good to be true. Scammers often lure players with unrealistic bonuses and promotions. Before claiming any bonuses, carefully read the terms and conditions to ensure transparency. Additionally, never share sensitive information such as passwords or financial details with anyone claiming to be from a casino. Legitimate online casinos will never ask for such information via email or chat.

Lastly, always practice responsible gambling habits. Set limits on your deposits, wagering, and playing time to avoid overspending. If you suspect any suspicious activity or feel uncomfortable while playing, contact the casino’s customer support immediately. By following these guidelines and staying vigilant, you can enjoy a safe and secure online gambling experience at Casinozoid.

As the online gambling industry continues to expand, staying vigilant against scams is paramount. By following the tips and strategies outlined in Casinozoid’s Guide to Safe Gambling, players can navigate the digital casino landscape with confidence. Remember to verify the legitimacy of online casinos, protect personal information, and exercise caution when making financial transactions. With a combination of knowledge and discernment, players can enjoy the thrill of online gambling while safeguarding themselves against potential scams. Stay informed, stay safe, and may your online gaming experiences always be enjoyable and secure.

Preliminary Steps

1. Enable the free shipping method in your desired shipping zone and set the free shipping setting to require a  “A valid free shipping coupon”.The setting can be done from WooCommerce >Settings >Shipping >Shipping zones. Select & Edit a Shipping method.

2. Decide the specific coupon for which when applied should set the shipping costs to zero(e.g. summer).

Preliminary Steps to setting all shipping methods' cost to zero for a free shipping coupon in WooCommerce?

3. Please make sure to enable the checkbox of  “Allow free shipping” of that specific coupon. If the checkbox is not enabled then it doesn’t change the shipping costs on the frontend.

Solution: Set All Shipping Methods’ Cost to Zero for all Free Shipping Coupon in WooCommerce

Let’s consider that a store owner who operates an online Clothing & Accessories store wants to clear out summer collections. So the code implemented below helps to adjust shipping costs to zero when a specific coupon, such as “summer,” is applied and with the configurations done in WooCommerce coupons as above.

add_filter( 'woocommerce_package_rates', 'ts_coupon_free_shipping', 20, 2 );
function ts_coupon_free_shipping( $rates, $package ) {
    $has_free_shipping = false;
    $applied_coupons = WC()->cart->get_applied_coupons();
    foreach( $applied_coupons as $coupon_code ){
        $coupon = new WC_Coupon($coupon_code);
        if($coupon->get_free_shipping()){
            $has_free_shipping = true;
            break;
        }
    }
    foreach( $rates as $rate_key => $rate ){
        if( $has_free_shipping ){
            // For other shipping methods (not 'free_shipping')
            if( $rate->method_id !== 'free_shipping'){
                // Append rate label titles (free)
                $rates[$rate_key]->label .= ' ' . __('(free)', 'woocommerce');
                // Set rate cost
                $rates[$rate_key]->cost = 0;
                // Set taxes rate cost (if enabled)
                $taxes = array();
                foreach ($rates[$rate_key]->taxes as $key => $tax){
                    if( $rates[$rate_key]->taxes[$key] > 0 )
                        $taxes[$key] = 0;
                }
                $rates[$rate_key]->taxes = $taxes;
            }
        }
    }
    return $rates;
}

Planning to add a LOCAL PICKUP option or let the user choose their delivery date on your WooCommerce store?

Meet Order Delivery Date pro that lets you set delivery date and time based on product category, shipping methods, pickup methods etc.

Let your customer choose a convenient delivery date and time set by you so that you can handle order fulfillment without any worries. It’s a win-win for both.

Output

Use case: Coupon that has enabled ‘Allow Free shipping’

In the below output, the summer coupon has been applied and hence the shipping costs are set to be zero. As we have already set the configuration of this ‘summer ‘ coupon to allow free shipping, it sets the costs of shipping methods to zero or free.

Use case: Coupon that has not enabled ‘Allow Free Shipping’

If any other coupons such as “flashsale” are applied the code will not change the shipping costs but instead shows the default rates configured in the shipping methods.

Code Explanation

Filter Registration:

  • The code begins by registering a filter in WooCommerce using add_filter.
  • The filter being used is ‘woocommerce_package_rates‘, which is a filter hook that allows modification of shipping rates.
  • The callback function that will handle this filter is ts_coupon_free_shipping.
  • Priority is set to 20, which determines the order in which filters are applied.
  • 2 is the number of arguments the callback function expects.

Callback Function Definition:

  • The ts_coupon_free_shipping function is defined with two parameters: $rates and $package.
  • $rates is an array that contains information about the available shipping rates, and $package holds information about the package being shipped.

Variable Initialization:

  • The code initializes a boolean variable $has_free_shipping and sets it to false. This variable will be used to track whether a free shipping coupon is applied.

Fetching Applied Coupons:

  • It fetches the list of applied coupons in the WooCommerce cart using $applied_coupons = WC()->cart->get_applied_coupons();.

Checking for Free Shipping Coupons:

  • A foreach loop iterates through each applied coupon code.
  • For each coupon, a WC_Coupon object is created, and the get_free_shipping() method is used to check if it offers free shipping.
  • If any coupon provides free shipping, the $has_free_shipping variable is set to true, and the loop breaks.

Modifying Shipping Rates:

  1. Another foreach loop iterates through each shipping rate in the $rates array.
  2. If $has_free_shipping is true (indicating a free shipping coupon is active), the code performs the following modifications for non-‘free_shipping’ methods:
  • Appends ‘(free)’ to the rate label to indicate that the shipping is free.
  • Sets the rate cost to 0, effectively making the shipping method free.

    3.Checks and sets the tax rate cost to 0 if taxes are enabled for the shipping method.

Returning Modified Rates:

  • Finally, the modified $rates array, reflecting the changes made to shipping methods, is returned from the function.

Solution: Set All Shipping Methods’ Cost to Zero for a Specific Coupon in WooCommerce

The above use cases work mainly based on the configuration of WooCommerce settings and the code. Also, it is applicable to all coupons that have “Allow free shipping” enabled. But if you don’t want to depend on settings and prefer using only a code snippet to set shipping costs for all shipping methods to 0 for specific coupons, this code can help.

NOTE: Refer to the coupon settings image that even though the ‘Allow Free shipping ‘ checkbox is not enabled, the code achieves to set all shipping methods to 0 cost.

// Hook into WooCommerce shipping rate calculation
add_filter('woocommerce_package_rates', 'ts_specific_coupon_free_shipping', 20, 2 );

// Define the function that adjusts shipping costs for the specific coupon
function ts_specific_coupon_free_shipping( $rates, $package ) {
    $specific_coupon_code = 'winter';

    $is_specific_coupon_applied = false;

    $applied_coupons = WC()->cart->get_applied_coupons();

    if (in_array($specific_coupon_code, $applied_coupons)) {
        $is_specific_coupon_applied = true;
    }

    $is_other_coupon_applied = count($applied_coupons) > 1;

    if( $is_specific_coupon_applied && !$is_other_coupon_applied ){
        foreach( $rates as $rate_key => $rate ){
            if( $rate->method_id === 'free_shipping'){
                $rates[$rate_key]->label = $rate->label;
            }
            else {
                $rates[$rate_key]->label .= ' ' . __('(free)', 'woocommerce');
                $rates[$rate_key]->cost = 0;
                $taxes = array();
                foreach ($rates[$rate_key]->taxes as $key => $tax){
                    if( $rates[$rate_key]->taxes[$key] > 0 )
                        $taxes[$key] = 0;
                }
                $rates[$rate_key]->taxes = $taxes;
            }
        }
    }

    return $rates;
}

Related Article: How to Disable Free Shipping Method After Applying a Coupon Code in WooCommerce?

Output

Use case: The specific coupon ‘winter’ is applied

Code Explanation

Step 1: Hook into WooCommerce Shipping Calculation

In the first step, we use the add_filter function to hook our custom function, ts_specific_coupon_free_shipping, into WooCommerce’s shipping rate calculation process. 

Step 2: Define the Custom Function

We define our custom function ts_specific_coupon_free_shipping. This function takes two parameters: $rates, which is an array representing shipping rates, and $package, which contains information about the package being shipped.

Step 3: Set the Target Coupon Code

We specify the coupon code we want to target. In this case, we set it to ‘winter’. This code will modify shipping rates only when this specific coupon is applied.

Step 4: Initialize Variables

We start by initializing a boolean variable, $is_specific_coupon_applied, to false. Additionally, we retrieve a list of applied coupons from the WooCommerce cart using WC()->cart->get_applied_coupons().

Step 5: Check If the Target Coupon Is Applied

Here, we check if the target coupon code (‘winter’) is among the applied coupons. If it is, we set $is_specific_coupon_applied to true, indicating that the specific coupon we’re targeting is applied.

Step 6: Check for Other Applied Coupons

We determine if any other coupons are applied by counting the number of applied coupons. If there is more than one applied coupon, we set $is_other_coupon_applied to true.

Step 7: Modify Shipping Rates

If the target coupon is applied (‘winter’) and no other coupons are applied, we enter a loop to modify each shipping rate.

Step 8: Modify Label for Free Shipping Method

For the ‘free_shipping’ method, we preserve its original label without adding ‘(free)’ to it. This ensures that free shipping remains as is.

Step 9: Modify Other Shipping Methods

For all other shipping methods, we append ‘(free)’ to their labels to indicate that they are now free of charge. We also set their cost to and ensure that any applied taxes are removed.

Step 10: Return Modified Shipping Rates

Finally, we return the modified shipping rates array, which will now reflect the changes we made based on the presence of the ‘winter’ coupon and the absence of any other coupons. 

Conclusion

The 1st code snippet above helps store owners offer free shipping on all shipping methods when customers apply any WooCommerce coupon code that has “Allow free shipping” enabled, thereby keeping regular shipping rates intact when a different coupon is used. The 2nd code snippet will achieve the same output but for a specific coupon code only. You can modify the code to apply free shipping to specific products or categories, even when a coupon is not used.

Let us know your thoughts on how the code was useful or any other queries in the comments section.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x