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( ( ! defined( 'WC_VERSION' ) || version_compare( WC_VERSION, '3.2.0', '<' ) ? WC()->cart->taxes : WC()->cart->get_cart_contents_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!', 'amount-left-free-shipping-woocommerce' ) ) ); } else { $placeholders = array( '%amount_left_for_free_shipping%' => wc_price( ( $min_free_shipping_amount - $total ) * $multiply_by ), '%free_shipping_min_amount%' => wc_price( ( $min_free_shipping_amount ) * $multiply_by ), '%current_cart_total%' => wc_price( ( $total ) * $multiply_by ), ); return str_replace( array_keys( $placeholders ), $placeholders, $content ); } } } } } if ( ! function_exists( 'alg_wc_get_left_to_free_shipping' ) ) { /* * alg_wc_get_left_to_free_shipping. * * @version 1.3.0 * @since 1.3.0 */ function alg_wc_get_left_to_free_shipping( $content, $multiply_by = 1 ) { return alg_get_left_to_free_shipping( $content, $multiply_by ); } } 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' ); add_shortcode( 'alg_wc_left_to_free_shipping', 'alg_get_left_to_free_shipping_shortcode_function' ); if ( ! function_exists( 'alg_wc_alfs_translate_function' ) ) { /** * alg_wc_alfs_translate_function. * * @version 1.3.0 * @since 1.3.0 */ function alg_wc_alfs_translate_function( $atts, $content = '' ) { // E.g.: `[alg_wc_left_to_free_shipping_translate lang="DE" lang_text="%amount_left_for_free_shipping% für kostenlosen Versand" not_lang_text="%amount_left_for_free_shipping% left for free shipping"]` if ( isset( $atts['lang_text'] ) && isset( $atts['not_lang_text'] ) && ! empty( $atts['lang'] ) ) { return ( ! defined( 'ICL_LANGUAGE_CODE' ) || ! in_array( strtolower( ICL_LANGUAGE_CODE ), array_map( 'trim', explode( ',', strtolower( $atts['lang'] ) ) ) ) ) ? $atts['not_lang_text'] : $atts['lang_text']; } // E.g.: `[alg_wc_left_to_free_shipping_translate lang="DE"]%amount_left_for_free_shipping% für kostenlosen Versand[/alg_wc_left_to_free_shipping_translate][alg_wc_left_to_free_shipping_translate not_lang="DE"]%amount_left_for_free_shipping% left for free shipping[/alg_wc_left_to_free_shipping_translate]` return ( ( ! empty( $atts['lang'] ) && ( ! defined( 'ICL_LANGUAGE_CODE' ) || ! in_array( strtolower( ICL_LANGUAGE_CODE ), array_map( 'trim', explode( ',', strtolower( $atts['lang'] ) ) ) ) ) ) || ( ! empty( $atts['not_lang'] ) && defined( 'ICL_LANGUAGE_CODE' ) && in_array( strtolower( ICL_LANGUAGE_CODE ), array_map( 'trim', explode( ',', strtolower( $atts['not_lang'] ) ) ) ) ) ) ? '' : $content; } } add_shortcode( 'alg_wc_left_to_free_shipping_translate', 'alg_wc_alfs_translate_function' );