cart->needs_shipping() || ! WC()->cart->show_shipping() ) { return; } $free_shipping_threshold = 0; $subtotal = WC()->cart->get_displayed_subtotal(); $classes = array( 'ux-free-shipping' ); $free_shipping_by_coupon = false; $ignore_discounts = false; // Check shipping packages. $packages = WC()->cart->get_shipping_packages(); $package = reset( $packages ); $zone = wc_get_shipping_zone( $package ); foreach ( $zone->get_shipping_methods( true ) as $method ) { if ( 'free_shipping' === $method->id ) { $free_shipping_threshold = $method->get_option( 'min_amount' ); if ( in_array( $method->get_option( 'requires' ), array( 'min_amount', 'either', 'both' ), true ) ) { $ignore_discounts = $method->get_option( 'ignore_discounts' ) === 'yes'; // Apply minimum order rule before coupon discount option. } } } // WPML. if ( class_exists( 'woocommerce_wpml' ) && ! class_exists( 'WCML_Multi_Currency_Shipping' ) ) { global $woocommerce_wpml; $multi_currency = $woocommerce_wpml->get_multi_currency(); if ( ! empty( $multi_currency->prices ) && method_exists( $multi_currency->prices, 'convert_price_amount' ) ) { $free_shipping_threshold = $multi_currency->prices->convert_price_amount( $free_shipping_threshold ); } } // Check coupons. if ( $subtotal && wc_coupons_enabled() ) { $coupons = WC()->cart->get_coupons(); foreach ( $coupons as $coupon ) { if ( ! $coupon->is_valid() ) continue; if ( $coupon->get_free_shipping() ) { $free_shipping_by_coupon = true; break; } $discount_amount = WC()->cart->get_coupon_discount_amount( $coupon->get_code(), WC()->cart->display_cart_ex_tax ); if ( ! $ignore_discounts && $subtotal >= $discount_amount ) { $subtotal -= $discount_amount; } } } $free_shipping_threshold = apply_filters( 'flatsome_shipping_free_shipping_threshold', $free_shipping_threshold ); if ( ! $free_shipping_threshold ) { return; } if ( $subtotal < $free_shipping_threshold && ! $free_shipping_by_coupon ) : $percent = floor( ( $subtotal / $free_shipping_threshold ) * 100 ); ?>