AI Verified

Name

WooCommerce autoselect Free shipping if available

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

TrendoDigital

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.

History

Last modified:

21/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:

Found 0 vulnerabilities

WooCommerce autoselect Free shipping if available

 
                    
1function action_woocommerce_before_cart() {
2 // NOT empty (get)
3 if ( count( WC()->session->get( 'shipping_for_package_0')['rates'] ) > 0 ) {
4 // Loop through
5 foreach ( WC()->session->get('shipping_for_package_0')['rates'] as $rate_id => $rate ) {
6 // For free shipping
7 if ( $rate->method_id == 'free_shipping' ) {
8 $default_rate_id = array( $rate_id );
9 break;
10 }
11 }
12 
13 // Set
14 WC()->session->set( 'chosen_shipping_methods', $default_rate_id );
15 }
16}
17add_action( 'woocommerce_before_cart', 'action_woocommerce_before_cart', 10, 0 );

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Quantity Based Shipping

Added: 1 year ago

Last Updated: 1 year ago

The snippet sets a shipping price of 2.50 if I buy 1-9 items and for 10+ we have free shipping

WooCommerce

AI Verified

1

WooCommerce Custom Text After Register Form Fields

Added: 1 year ago

Last Updated: 2 weeks ago

This guide shows you how you can add any custom text below the form fields on the Register form on the My Account page.

WooCommerce

AI Verified

1

WooCommerce Stock Status Progress Bar for Variations

Added: 1 year ago

Last Updated: 2 weeks ago

An expanded on version of ecommercehints.com's WooCommerce Stock Status Progress Bar This snippet inserts a progress bar on both single products and variable products' pages, allowing customers t...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

0

WooCommerce PDF Invoice - Remove all invoices

Added: 1 year ago

Last Updated: 1 year ago

Remove all generated invoices from the plugin WooCommerce PDF Invoice

General

AI Verified

0

Remove Query String - ver

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Hide Fields if Virtual @ WooCommerce Checkout

Added: 1 year ago

Last Updated: 1 year ago