Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

279
Visualizações
Custom add to cart button doesn't work if manage stock level at product level

I just have a little question on a custom add to cart button I have created on the shop page.

If you view the screenshot below, if you click the add to cart button (the one with the price associated), it will display the options for the user (quantity, variations, add to cart button etc).

enter image description here

However, I notice if a product is set so that it manages stock at product level, the add to cart button (one with price associated) doesn't work (as nothing happens). Not sure why it's not working when this setting is set. Can somebody help?

enter image description here

Here is the code:

/**
 * Replace add to cart button in the loop.
 */
function iconic_change_loop_add_to_cart() {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    add_action( 'woocommerce_after_shop_loop_item', 'iconic_template_loop_add_to_cart', 10 );
}

add_action( 'init', 'iconic_change_loop_add_to_cart', 10 );


function iconic_template_loop_add_to_cart() {
    global $product;

    woocommerce_template_single_add_to_cart();
}

/**
 * Customise variable add to cart button for loop.
 *
 * Remove qty selector and simplify.
 */
function iconic_loop_variation_add_to_cart_button() {
    global $product;

    ?>
    <div class="woocommerce-variation-add-to-cart variations_button">
        <button type="submit" class="single_add_to_cart_button button"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
        <input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
        <input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
        <input type="hidden" name="variation_id" class="variation_id" value="0" />
    </div>
    <?php
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

With given little info it is very hard to find the bug. Please follow the below steps -

  1. Hard reload the browser, and check if there are fatal js error in console and resolve those first.
  2. If the add-to-cart button is not appearing for variable product - make sure you have put the price for variation
  3. If the issue is still there - find the code for following hook(s) and edit the question description
  • woocommerce_product_single_add_to_cart_text
  • woocommerce_variable_add_to_cart
  • woocommerce_ajax_variation_threshold
  • woocommerce_before_variations_form
  • woocommerce_variation_is_visible

Also as GhostPengy says give us the code from the iconic_loop_variation_add_to_cart_button is called.

Follow the above steps and if it is not resolved give us more code to identify the bug precisely.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda