requires, array( 'min_amount', 'either', 'both' ) ) ) { $min_free_shipping_amount = $free_shipping->min_amount; } } else { $legacy_free_shipping = new WC_Shipping_Legacy_Free_Shipping(); if ( 'yes' === $legacy_free_shipping->enabled ) { if ( in_array( $legacy_free_shipping->requires, array( 'min_amount', 'either', 'both' ) ) ) { $min_free_shipping_amount = $legacy_free_shipping->min_amount; } } if ( 0 == $min_free_shipping_amount ) { if ( function_exists( 'WC' ) && ( $wc_shipping = WC()->shipping ) && ( $wc_cart = WC()->cart ) ) { if ( $wc_shipping->enabled ) { if ( $packages = $wc_cart->get_shipping_packages() ) { $shipping_methods = $wc_shipping->load_shipping_methods( $packages[0] ); foreach ( $shipping_methods as $shipping_method ) { if ( 'yes' === $shipping_method->enabled && 0 != $shipping_method->instance_id ) { if ( 'WC_Shipping_Free_Shipping' === get_class( $shipping_method ) ) { if ( in_array( $shipping_method->requires, array( 'min_amount', 'either', 'both' ) ) ) { $min_free_shipping_amount = $shipping_method->min_amount; break; } } } } } } } } } if ( 0 != $min_free_shipping_amount ) { if ( isset( WC()->cart->cart_contents_total ) ) { $total = ( WC()->cart->prices_include_tax ) ? WC()->cart->cart_contents_total + array_sum( WC()->cart->taxes ) : WC()->cart->cart_contents_total; if ( $total >= $min_free_shipping_amount ) { return do_shortcode( get_option( 'alg_wc_left_to_free_shipping_info_content_reached', __( 'You have free delivery!', 'left-to-free-shipping-for-woocommerce' ) ) ); } else { $content = str_replace( '%amount_left_for_free_shipping%', wc_price( ( $min_free_shipping_amount - $total ) * $multiply_by ), $content ); $content = str_replace( '%free_shipping_min_amount%', wc_price( ( $min_free_shipping_amount ) * $multiply_by ), $content ); return $content; } } } } } if ( ! function_exists( 'alg_get_left_to_free_shipping_shortcode_function' ) ) { /* * alg_get_left_to_free_shipping_shortcode_function. * * @version 1.0.0 * @since 1.0.0 */ function alg_get_left_to_free_shipping_shortcode_function( $atts, $content ) { $atts = shortcode_atts( array( 'content' => '', 'multiply_by' => 1 ), $atts, 'alg_get_left_to_free_shipping' ); return alg_get_left_to_free_shipping( $atts['content'], $atts['multiply_by'] ); } } add_shortcode( 'alg_get_left_to_free_shipping', 'alg_get_left_to_free_shipping_shortcode_function' );