close
Skip to content

Products added to cart in WooCommerce without clicking on Add to Cart button when Speculative Loading active #1140

@westonruter

Description

@westonruter

Bug Description

As reported on the support forum, users browsing a site with WooCommerce and the Speculative Loading plugin can end up getting products added to their shopping cart by just hovering over the Add to Cart button when in moderate eagerness (the default setting). What's worse is when the eager eagerness setting is enabled, all the products on the page can be added to the cart just by visiting the page.

Steps to reproduce

  1. Activate and configure WooCommerce (and install the Storefront theme, perhaps)
  2. Activate the Speculative Loading plugin
  3. Access the shop page and hover over an Add to Cart button

Screenshots

Screen.recording.2024-04-15.11.49.08.webm

Additional Context

When not using a block theme, this is the code to create the add-to-cart button:
https://github.com/woocommerce/woocommerce/blob/a8e84d8c8b20558f66ed33dcbee6c1dec300752f/plugins/woocommerce/includes/wc-template-functions.php#L1363-L1403
https://github.com/woocommerce/woocommerce/blob/a8e84d8c8b20558f66ed33dcbee6c1dec300752f/plugins/woocommerce/templates/loop/add-to-cart.php#L27-L32

Note an a tag is always used. Contrast with the block code:
https://github.com/woocommerce/woocommerce/blob/a8e84d8c8b20558f66ed33dcbee6c1dec300752f/plugins/woocommerce/src/Blocks/BlockTypes/ProductButton.php#L74-L231

Here a button is used when AJAX is enabled.

In both cases, however, rel=nofollow is present (although it can be filtered out by the woocommerce_loop_add_to_cart_args filter). It's unfortunate that since these add-to-cart links aren't idempotent (i.e. they have an action) that they don't also have _wpnonce query parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Speculative LoadingIssues for the Speculative Loading plugin (formerly Speculation Rules)[Type] BugAn existing feature is broken

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions