-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Validate variation attributes in WC_Cart::add_to_cart() #27115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
jonathansadowski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning up my previous fix so that it also works with ajax and using WC()->cart->add_to_cart(). I've verified that it now works in those cases (and still works with request variables), and the news tests / changes to the test make sense to me 👍
|
This is what I get when testing the urls:
Am I doing something wrong or missing some additional setup? |
It depends on your product, have you imported the product I submitted?
If you are using the same steps it suppose to never require a color, since the color isn't a "any" attribute, but if you have changed to Any attribute that is set doesn't require an attribute if you already is using the variation_id, yet it's required for those attributes using |
rrennick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@claudiosanches Tested great for me.
|
This is good to merge once conflicts are addressed. |
|
@Konamiman You are testing correctly.
This message is correct with the patch. The color suppose to be required, since it's empty now, at least on value need to inserted. |
|
Hello. I am also having this problem. Only need to add the piece of code in the files? Thank you |

All Submissions:
Changes proposed in this Pull Request:
Currently there's only validation of variation attributes inside
WC_Form_Handler::add_to_cart_handler_variable()by checking$_REQUEST, but there's no validation if you are using AJAX or usingWC()->cart->add_to_cart()directly, allowing inconsistent behavior while adding variable products to the cart.I hope with those changes fix the issues reported in #25133.
This PR fixes also a small bug when using:
It allows products with
anyattributes to get included into the cart without asking for an attribute.Closes #25133.
How to test the changes in this Pull Request:
?add-to-cart=<variation_id>&attribute_size=?add-to-cart=<parent_product_id>&variation_id=<variation_id>&attribute_size=WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $attributes_list ).Other information:
Changelog entry