Answer the question
In order to leave comments, you need to log in
How to hide the shipping method until a certain amount has been accumulated in the cart?
Hello everybody! There was such a problem: you need to hide the delivery method until the site’s basket contains goods worth 5000 rubles. I've searched through a lot of information, but there is no answer anywhere. I understand I need to find the variable where the total is stored? How to implement this please tell me?
Answer the question
In order to leave comments, you need to log in
I'm correcting the answer. I am writing for this issue. I liked the style answer below.
It will add another js file in the cart and track the amount. If the sum is less than 5000, then hide this method with styles.
like display:none;
Checking can be hung up on pressing buttons and when loading the page.
What is the problem?
Assume something like this for an example:
<div class="summary_block">
<span class="summary">3000</span>руб.
<input id="summary" type="hidden" value="3000">
</div>
<div class="delivery_method hide">Описания или форма или что там у тебя</div>
<div class="product_grid">
<div class="product_item">
<p>Описание товара</p>
<a href="/buy" id="product_buy" data-id="100">В корзину</a>
</div>
<div class="product_item">
<p>Описание товара</p>
<a href="/buy" id="product_buy" data-id="101">В корзину</a>
</div>
<div class="product_item">
<p>Описание товара</p>
<a href="/buy" id="product_buy" data-id="101">В корзину</a>
</div>
</div>
.hide {
display: none;
}
jQuery(document).on('load', function() {
jQuery('#product_buy').on('click', function(e) {
e.preventDefault(); // Сбрасываю клик по ссылке, так как скорее всего тут должно быть что-то еще для добавления товара в корзину
let summary = jQuery('#summary').val(); // Получаю число из скрытого поля
if(Number(summary) >= 5000) { // Проверяю соответствует ли оно требуемому и если да, показываю блок
jQuery('.delivery_method').removeClass('hide');
} else { // Иначе скрываю блок обратно
jQuery('.delivery_method').addClass('hide');
}
});
Alternatively, you can try various plugins.
For example - WooCommerce Cart Based Shipping
Shipping base on the cart's subtotal, number of items ordered, or total weight of all items combined
Set a minimum or maximum requirement the customer must meet (based on calculation method)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question