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).
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?
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
}
With given little info it is very hard to find the bug. Please follow the below steps -
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.