Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda