K
K
kirill2709992020-06-18 23:31:33
WordPress
kirill270999, 2020-06-18 23:31:33

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

3 answer(s)
S
serg1764, 2020-06-19
@serg1764

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.

W
WTERH, 2020-06-19
@Expany

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>

Drop styles:
.hide {
    display: none;
}

A bit of js (I focus on jQuery, since WordPress has it out of the box):
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');
        }
    });

The variant excludes the wookomers, since I noticed the tag after I riveted the example (´• ω •`)
And the wokomers itself did not work.
But I will assume that it is worth looking at the theme template, if the basket is in the header, then I will assume some kind of header.php
From there, you can push off and understand where to dig (if not very tricky). ¯\_(ツ)_/¯

O
Orkhan Hasanli, 2020-06-19
@azerphoenix

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 question

Ask a Question

731 491 924 answers to any question