G
G
Grayni Web2017-02-05 15:01:01
PHP
Grayni Web, 2017-02-05 15:01:01

How to implement an informer on each product page, N rubles left before free delivery?

We need to create an informer that displays the difference between the amount in the cart and the minimum order amount for free shipping. I am not strong in PHP.
Initial conditions: the minimum order amount is 1500 rubles, at which free shipping is included, this is already working by default. But I need that when a user adds a product to the cart, he sees on any page or in the header (this is not so important) how much more he needs to add to display the notification "Bonus: free shipping!".
Found the following code WC ()->cart->get_cart_subtotal () - displays the sum of all added goods to the cart.
How to write 1500 - WC()->cart->get_cart_subtotal()?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WQP, 2017-02-05
@Grayni

$total = WC()->cart->get_cart_subtotal();
$min = 1500;
$difference = $min - intval($total);

if ($difference <= 0) {
    echo "Доставка бесплатная";
} else {
    echo "Для бесплатной доставки пополните корзину на $difference";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question