-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Restore pre-7.2.0 quantity selector behavior #36460
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
Prior to 7.2.0 the quantity input was hidden if input min and max were identical (either because the product was sold individually, or because of min/max products config). This change restores that behavior, but makes it possible to render the input in readonly mode if desired (via filters).
Test Results SummaryCommit SHA: 01b420b
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Prior to 7.2.0 the quantity input was hidden if input min and max were identical (either because the product was sold individually, or because of min/max products config). This change restores that behavior, but makes it possible to render the input in readonly mode if desired (via filters).
Prior to 7.2.0 the quantity input was hidden if input min and max were identical (either because the product was sold individually, or because of min/max products config). This change restores that behavior, but makes it possible to render the input in readonly mode if desired (via filters).
|
@barryhughes I have a problem with the snippet of code you provided. I have products in the basket that can be purchased individually (quantity input type="text") and those that can be purchased in any quantity (quantity input type="number"). Unfortunately, adding the filter below makes all inputs change to "text" type: // Convert into a text input. |
|
Hi @pe-pe80,
If you only copied those 4 lines from the code I shared in the testing instructions, and not the larger snippet in its entirety, then it will indeed change all inputs to be of type 'text'. However, the testing instructions were chiefly created for the purposes of testing the PR—and not for any other reason. If I'm misunderstanding, though, and you are trying to describe a bug of some kind that might have been introduced via this PR, please do create a bug report and we'll definitely look into it 👍 |
|
Hi @barryhughes! Sorry I wasn't very precise. I used all the code. I just wanted to point out the problematic part here. From the moment you use the "woocommerce_quantity_input_type filter," all subsequent products will have a "text" quantitative input. Suppose I have such products in the shopping cart:
I want to get this effect:
Unfortunately, after applying the code you proposed (the whole code), the cart looks like this:
|
|
Gotcha. Yes, you're right. So, in your case, you would probably want the filter to unhook itself ... but again, just to be clear, the snippet in the testing instructions was a simple snippet that worked for the purposes of testing this change—it wasn't intended for general use—so it's not too surprising there are real world cases where it starts breaking down. |
|
I modified the code like this and it works fine now :) add_filter('woocommerce_quantity_input_args', function (array $args) {
if ($args['max_value'] < 1 || $args['min_value'] !== $args['max_value']) {
remove_filter('woocommerce_quantity_input_type', 'change_quantity_input_type');
return $args;
}
add_filter('woocommerce_quantity_input_type', 'change_quantity_input_type');
$args['readonly'] = true;
return $args;
});
function change_quantity_input_type() {
return 'text';
} |
The product quantity selector has gone through a number of changes. To understand this latest PR, I want to start by summarizing its recent history:
So, in this change, we essentially restore the behavior we had before the 7.2.0 release. However, we are also tweaking an existing filter hook and adding one more, making it possible to achieve the objectives of the original PR without implementing a template override.
Updates #36007.
How to test the changes in this Pull Request:
Let's now test that we can achieve the goals of PR#34282 by adding the following code to an appropriate location (such as
wp-content/mu-plugins/test-quantity-selectors.php):Now, if you repeat the above tests, you should find the quantity selector always displays, even for products that are sold individually. However, in these cases it will be a readonly text input.
Other information:
pnpm --filter=<project> changelog add?FOR PR REVIEWER ONLY: