• I’m trying to add a minimum order notice depending on the shipping zone.

    Example:
    Zone 1 = minimum £25
    Zone 2 = minimum £60

    I’ve added a function on my functions.php to get the shipping zone but it is not dynamic and will not update.

    if( is_cart() || is_checkout() ) {
    		global $woocommerce;
    
    		// Set minimum cart total
    		$minimum_cart_total = 0;
    
    		$WC_Shipping_Zone = WC_Shipping_Zones::get_zone_matching_package( $package );
    		$shipping_methods = $WC_Shipping_Zone->get_shipping_methods( true );
    		$zone = $WC_Shipping_Zone->get_zone_name();
    
    		if($zone == 'Zone 1') {
      		$minimum_cart_total = 25;
    		} else if($zone == 'Zone 2') {
      		$minimum_cart_total = 60;
    		} else {
      		$minimum_cart_total = 0;
    		}
    
    		$total = WC()->cart->subtotal;
    
    		if( $total <= $minimum_cart_total  ) {
    			// Display our error message
    			wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
    				.'<br />Current cart\'s total: %s %s',
    				$minimum_cart_total,
    				get_option( 'woocommerce_currency'),
    				$total,
    				get_option( 'woocommerce_currency') ),
    			'error' );
    		}
    	}

    This, picks the address from the user accounts details rather than dynamically from e.g. ‘calculate shipping form’. How can I achieve this? The debug mode in shipping options does what I need. Can I do a minimum order on shipping zone in a different way?

    I did setup an ajax request on the front-end to call this function but it will not update the shipping zone.

    • This topic was modified 7 years, 7 months ago by generalgumus.
  • The topic ‘Get shipping zone – ajax’ is closed to new replies.