AI Verified

Name

WooCommerce Spend £X To Unlock Free Shipping

About

Native WooCommerce functionality means you can achieve this by setting am minimum order amount under the free shipping method options. However, this guide goes one step forward and bypasses these options. This guide allows you to display a message on the cart and checkout pages letting users know that free shipping is disabled unless they spend a certain amount. In this particular guide, we’ve disabled the shipping method, Free Shipping, unless the customer’s cart adds up to £50. On the cart and checkout pages, a message will appear above the totals breakdown stating the amount required for Free Shipping to be unlocked. Once the cart adds up to £50 or more, a message appears “You’ve unlocked Free Shipping”. Depending on your business requirements, you’ll need to tweak the free shipping threshold price. You’ll also need the shipping method radio button value which is explained further on.

Language

PHP

Rating

Voted: 1 by 1 user(s)

How to Setup Snippet

Simply copy the pre-coded solution to your active child theme’s functions.php or preferably the Code Snippets Plugin.

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://www.ecommercehints.com/woocommerce-spend-x-to-unlock-free-shipping

Codevault

ecommercehints

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://www.ecommercehints.com/

History

Last modified:

14/11/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

-------------------------------------------------------------------------------------------------------------
Name | Potential vulnerability found : Cross Site Scripting
Line | 21
Code | echo('You\'re ' . get_woocommerce_currency_symbol() . $cart_remaining . ' away from free shipping!<br><progress id="freeshippingprogress" max="50" value="'.$cart_total.'"></progress>')
Code | Line | 20 : $cart_remaining = 50 - $cart_total);

Name | Potential vulnerability found : Cross Site Scripting
Line | 33
Code | echo('Spend another ' . get_woocommerce_currency_symbol() . $cart_remaining . ' for free shipping!<br><progress id="freeshippingprogress" max="50" value="'.$cart_total.'"></progress>')
Code | Line | 20 : $cart_remaining = 50 - $cart_total);

Found 2 vulnerabilities

WooCommerce Spend £X To Unlock Free Shipping

 
                    
1/**
2 * Snippet Name: WooCommerce free shipping if subtotal is over specific amount.
3 * Snippet Author: ecommercehints.com
4 */
5 
6// Enable/disable the shipping method. Only include this function if you haven't enabled free shipping rules in the shipping method settings for Free Shipping.
7add_filter( 'woocommerce_package_rates', 'ecommercehints_free_shipping_for_specific_products', 10, 2 );
8function ecommercehints_free_shipping_for_specific_products($rates, $package) {
9 $cart_total = WC()->cart->get_subtotal();
10 if ($cart_total < 50 ) {
11 unset( $rates['free_shipping:3'] ); // The shipping method radio button value
12}
13return $rates;
14}
15 
16// Show 'Spend another X amount' on cart page.
17add_filter( 'woocommerce_cart_totals_before_shipping', 'ecommercehints_cart_page_progress_bar', 10 );
18function ecommercehints_cart_page_progress_bar() {
19 $cart_total = WC()->cart->get_subtotal();
20 $cart_remaining = 50 - $cart_total;
21 if ($cart_total < 50 ) {
22 echo 'You\'re ' . get_woocommerce_currency_symbol() . $cart_remaining . ' away from free shipping!<br><progress id="freeshippingprogress" max="50" value="'.$cart_total.'"></progress>';
23 } else {
24 echo 'You\'ve unlocked free shipping!';
25 }
26};
27 
28// Show 'Spend another X amount' on checkout.
29add_filter( 'woocommerce_checkout_before_order_review', 'ecommercehints_checkout_page_progress_bar', 10 );
30function ecommercehints_checkout_page_progress_bar() {
31 $cart_total = WC()->cart->get_subtotal();
32 $cart_remaining = 50 - $cart_total;
33 if ($cart_total < 50 ) {
34 echo 'Spend another ' . get_woocommerce_currency_symbol() . $cart_remaining . ' for free shipping!<br><progress id="freeshippingprogress" max="50" value="'.$cart_total.'"></progress>';
35 } else {
36 echo 'You\'ve unlocked free shipping!';
37 }
38};

1

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

1

Hide Other Shipping Methods When Free Shipping Available

Added: 1 year ago

Last Updated: 1 year ago

Hide Other Shipping Methods When Free Shipping Available

WooCommerce

AI Verified

0

Btn Woocommerce

Added: 3 months ago

Last Updated: 3 months ago

Remove btn na página de produto (alguns produtos)

WooCommerce

Pro Verified

4

Add the Sold Column to Products in the Wordpress Dashboard

Added: 1 year ago

Last Updated: 2 weeks ago

Wouldn't you like to know how many of an item you'd sold?

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

5

WooCommerce Show Number Of People Viewing Product

Added: 1 year ago

Last Updated: 11 months ago

We want to make this solution absolutely clear from the outset. This snippet does NOT generate the actual number of people viewing the product. It shows a randomly generated number in the range of two...

WooCommerce

AI Verified

4

WooCommerce Show Number Of Units Sold On Product Page

Added: 1 year ago

Last Updated: 6 months ago

Showing the number of product units sold on the single product page is a great way to introduce Fear Of Missing Out (FOMO). You can highlight how many products are sold to let customers know a product...

WooCommerce

AI Verified

2

WooCommerce Add Content Under The Proceed To Checkout Button On The Cart Page

Added: 1 year ago

Last Updated: 11 months ago

How many times have you bought something online and seen trust symbols near the proceed to checkout button on the cart page? “30 Day Money Back Guarantee” or “Secure Checkout” are popular examples. By...