Last active
November 11, 2020 21:53
-
-
Save trvswgnr/cb2844d0459473cd448c3896e551fd04 to your computer and use it in GitHub Desktop.
Get minimum for free shipping set in WooCommerce settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get free shipping minimum | |
* | |
* @param string $zone_name Zone name. | |
* @return int $min_amount Minimum for free shipping. | |
*/ | |
function get_free_shipping_minimum( $zone_name = '' ) { | |
if ( empty( $zone_name ) ) { | |
return null; | |
} | |
$min_amount = 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 ( 'free_shipping' === $method->id ) { | |
$free_shipping_method = $method; | |
break; | |
} | |
} | |
if ( $free_shipping_method ) { | |
$min_amount = $free_shipping_method->min_amount; | |
} | |
} | |
return (int) $min_amount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment