How to get the minimum order amount for free shipping in woocommerce

How can I get the minimum order quantity needed to receive free shipping ( woocommerce_free_shipping_min_amount , which is installed in wap.microsoft → Settings → Shipping → Free shipping → minimum order amount) in woocommerce?

I want to display this price on the first page

+7
php wordpress woocommerce shipping
source share
2 answers

This value is stored in option under the woocommerce_free_shipping_settings key. This is the array that is loaded by WC_Settings_API->init_settings() .

If you want to access it directly, you can use get_option() :

 $free_shipping_settings = get_option( 'woocommerce_free_shipping_settings' ); $min_amount = $free_shipping_settings['min_amount']; 
+8
source share

The accepted answer no longer works with WooCommerce version 2.6. It still gives a way out, but this conclusion is erroneous because it does not use the newly entered delivery zones.

To get the minimum cost for free shipping in a specific area, try this function:

 /** * Accepts a zone name and returns its threshold for free shipping. * * @param $zone_name The name of the zone to get the threshold of. Case-sensitive. * @return int The threshold corresponding to the zone, if there is any. If there is no such zone, or no free shipping method, null will be returned. */ function get_free_shipping_minimum($zone_name = 'England') { if ( ! isset( $zone_name ) ) return null; $result = null; $zone = null; $zones = WC_Shipping_Zones::get_zones(); foreach ( $zones as $z ) { if ( $z['zone_name'] == $zone_name ) { $zone = $z; } } if ( $zone ) { $shipping_methods_nl = $zone['shipping_methods']; $free_shipping_method = null; foreach ( $shipping_methods_nl as $method ) { if ( $method->id == 'free_shipping' ) { $free_shipping_method = $method; break; } } if ( $free_shipping_method ) { $result = $free_shipping_method->min_amount; } } return $result; } 

Put the above function in functions.php and use it in the template as follows:

 $free_shipping_min = '45'; $free_shipping_en = get_free_shipping_minimum( 'England' ); if ( $free_shipping_en ) { $free_shipping_min = $free_shipping_en; } echo $free_shipping_min; 

Hope this helps someone.

+2
source share

All Articles