Created
December 19, 2021 11:55
-
-
Save artikus11/a4ad172da3f4082ad191e5c3e6927e06 to your computer and use it in GitHub Desktop.
Вывод сообщения о бесплатной доставке
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Вывод сообщения о бесплатной доставке | |
* | |
* @testedwith WooCommerce 5.5 | |
* @author Artem Abramovich | |
*/ | |
function free_shipping_cart_notice() { | |
// Сумма от которой считается бесплатная доставка | |
$min_amount = 100000; | |
// Текущее значение заказа | |
$current = WC()->cart->get_subtotal(); | |
$output = '<div class="mini-cart-shipping" style="text-align: center;margin-bottom:1em;">'; | |
if ( $current && $current < $min_amount ) { | |
// Сколько осталось до бесплатной доставки | |
$cart_difference = wc_price( $min_amount - $current ); | |
// Сообщение об бесплатной доставке | |
$message = 'До бесплатной доставки осталось <strong>%%cart_difference%%</strong>'; | |
// Подмена %%cart_difference%% на расчетнойе значение остатка | |
$message = str_replace( '%%cart_difference%%', $cart_difference, $message ); | |
$output .= sprintf( | |
'<span class="mini-cart-shipping-message">%s</span><span class="mini-cart-shipping-progress-wrap" style="display: block;margin-top: 1rem;background: #cbd5e0;height: 10px;border-radius: 3px;overflow: hidden;"><span class="mini-cart-shipping-progress" style="width:%s%%;background: #f27676;height: 100%%;display: block;"></span></span>', | |
$message, | |
esc_attr( ( $current / $min_amount ) * 100 ) | |
); | |
} | |
$output .= '</div>'; | |
echo $output; | |
} | |
add_action( 'woocommerce_before_mini_cart', 'free_shipping_cart_notice' ); | |
add_action( 'woocommerce_before_cart_table', 'free_shipping_cart_notice' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment