Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!