添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Prevent ajax adding_to_cart conditionally #25759

Closed
@helgatheviking

Description

@helgatheviking

Is your feature request related to a problem? Please describe.

The ajax add to cart feature send an ajax request when the ajax add to cart button is clicked. I would like a way to prevent this ajax call from firing if certain conditions are not met.

Here's the script src

And there's a trigger in there just beforehand, but as far as I know, there's no way to hook into that trigger and prevent the code from proceeding.

// Trigger event.
$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] );

While generally simple products require no validation, there are times when plugins (like Name Your Price) might add fields that need validating, yet still want to take advantage of ajax add to cart.

In PHP we could use apply_filters to validate the product (and you do use that validating via woocommerce_add_to_cart_validation). I'd like to propose a JS alternative.

Describe the solution you'd like
Some kind of condition/flag that will prevent the add to cart ajax call from firing. I'm proposing the same thing in One Page Checkout and it could make sense if you both used the same condition.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

Labels

type: task The issue is an internally driven task (e.g. from another A8c team).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions