M
M
MisTFoR2020-12-07 00:55:02
WooCommerce
MisTFoR, 2020-12-07 00:55:02

How to disconnect the "Add to Cart" button from the button with the choice of the number of products?

Hello.
I have an "Add to Cart" button in the product card and a field with a choice of the number of products (as usual) next to it. Question: how to disconnect this button, for example, add it to the product description, but what would it also work with the product quantity field?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fink, 2020-12-07
@MisTFoR

As an option, you can do this:
1. Hide the quantity field via css

.single-product .quantity .qty {
    display: none;
}

2. Remove the output of the add button by default and display it in the right place on the page through the hook
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 45 ); //В сторфронт выводим после мета описания

3. Add a new quantity field through the hook where you need it and use js to change the hidden quantity field next to the add to cart button
add_action('woocommerce_single_product_summary', 'fink_new_qty_add_to_cart', 30 ); //Добавляем новое поле кол-ва туда где была кнопка добавления в корзину
function fink_new_qty_add_to_cart() {

    echo '<input type="number" class="new_qty" value="1">';

    ?>

    <script>
    jQuery(document).ready(function($) {

        $('.new_qty').on('change', function(e) {
            var qty = $(this);
            $('.quantity .qty').val(qty.val());
        });

    });
    </script>

    <?php
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question