• Resolved Nomadsteam

    (@nomadsteam)


    Hi,

    Seems there is an issue with the “Products by Category” block.

    When the Ajax Add to Cart option is activated in the WooCommerce Settings and out of stock products are displayed in the loop, the “Read more” link launches the Ajax request while it should be a simple link pointing to the product page.

    So when the user clicks on the link, the spinner is displayed and he’s then redirected to the product page with the error “You cannot add “%s” to the cart because the product is out of stock”.

    If you inspect the code, you can see the “ajax_add_to_cart” class added to the “Read more” links.

    Products by Category block -> Read More link:

    <a href="" class="wp-block-button__link add_to_cart_button ajax_add_to_cart">Read more</a>

    [File] woocommerce\packages\woocommerce-blocks\src\BlockTypes\AbstractProductGrid.php (Line 488)

    if ( $product->supports( 'ajax_add_to_cart' ) ) {
    	$attributes['class'] .= ' ajax_add_to_cart';
    }

    On the WooCommerce archive pages, the link works fine tho.

    Shop archives -> Read More link:

    <a href="" class="button product_type_simple">Read more</a>

    [File] woocommerce\includes\wc-template-functions.php (Line 1291)

    $product->supports( 'ajax_add_to_cart' ) && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : ''

    Is this an omission in the code or am I missing something?

    Thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Products by Category] Ajax Add to Cart on Out of stock products’ is closed to new replies.