$content = 'Вам не хватает %left_to_free% до бесплатной доставки.<br>Всего нужно %free_shipping_min_amount% ';
$free_text = get_left_to_free_shipping( $content );
function get_left_to_free_shipping( $content, $multiply_by = 1 ) {
if ( '' == $content ) {
$content = __( '%left_to_free% left to free shipping', 'woocommerce-jetpack' );
}
$min_free_shipping_amount = 0;
$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;
}
}
}
}
}
}
}
}
$free_shipping = new WC_Shipping_Free_Shipping();
if ( in_array( $free_shipping->requires, array( 'min_amount', 'either', 'both' ) ) ) {
$min_free_shipping_amount = $free_shipping->min_amount;
}
if ( 0 != $min_free_shipping_amount ) {
if ( isset( WC()->cart->cart_contents_total ) ) {
$cart_taxes = ( WCJ_IS_WC_VERSION_BELOW_3_2_0 ? WC()->cart->taxes : WC()->cart->get_cart_contents_taxes() );
$total = ( WC()->cart->prices_include_tax ) ? WC()->cart->cart_contents_total + array_sum( $cart_taxes ) : WC()->cart->cart_contents_total;
if ( $total >= $min_free_shipping_amount ) {
return do_shortcode( get_option( 'wcj_shipping_left_to_free_info_content_reached', __( 'You have Free delivery', 'woocommerce-jetpack' ) ) );
} else {
$content = str_replace( '%left_to_free%', 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;
}
}
}
return $content;
}