Getting minimum order amount for 'Free Shipping' method in checkout page

前端 未结 5 1715
醉话见心
醉话见心 2021-01-06 02:42

I have did tried to use the code from this answer:
How to get minimum order amount for free shipping in woocommerce

But it return a NULL

5条回答
  •  清酒与你
    2021-01-06 02:58

    Right way for get this..

    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;
    }
    

提交回复
热议问题