Not working with custom add-to-cart link
-
I’m developing a theme where we want to use the pro version of this plugin (I’m developing with the free one though). Unfortunately, when I create my own add-to-cart Button/Link, the ajax add to cart ist not really working. After I click my custom button, the page gets reloaded and then the side card is shown (on the new page). But I obviously don’t want it to reload.
This is my filter to customize the cart button:
add_filter('woocommerce_loop_add_to_cart_link', function ($array, $product) { return sprintf( ' <a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="fh__product__add-to-cart %s product_type_%s"> <img src="' . asset_path('images/shopping-bag.svg') . '" class="fh__product-icon" width="100%%" height="100%%"/> </a>', esc_url($product->add_to_cart_url()), esc_attr($product->get_id()), esc_attr($product->get_sku()), esc_attr(isset($quantity) ? $quantity : 1), $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button icon-shopping-cart' : '', esc_attr($product->get_type()), esc_html($product->add_to_cart_text()) ); }, 10, 2);
I observed that my custom button does not get the class
ajax_add_to_cart
. The default button does get this class. But I could not find any place in your plugins code where this class gets added to the button.Please point me in the right direction to get this working.
- The topic ‘Not working with custom add-to-cart link’ is closed to new replies.