Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1202958
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 2 years ago.
Improve this questionI have products where I need to disable the quantity field on the product detail pages and dynamically change the quantity based on another value.
I change the value using this code:
if (jQuery('body').hasClass('is-adapt-quantity-product')) {
jQuery('.wc-pao-addon-custom-textarea').bind('keyup', _.debounce(function(){
jQuery(".qty").val(parseInt(jQuery(this).val().length));
}, 500));
}
This works fine. The quantity changes and if I click on the "add to cart" button, I have the quantity in my cart.
When I add this to the js code:
jQuery(".qty").attr("disabled", "disabled");
The quantity on the product detail page changes. However when I add the product to the cart, it adds always just the quantity of "1".
Does anybody know why this happens and how I can prevent this from happening? I want to disable the quantity field, because the field should be changes dynamically...
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 2 years ago.
Improve this questionI have products where I need to disable the quantity field on the product detail pages and dynamically change the quantity based on another value.
I change the value using this code:
if (jQuery('body').hasClass('is-adapt-quantity-product')) {
jQuery('.wc-pao-addon-custom-textarea').bind('keyup', _.debounce(function(){
jQuery(".qty").val(parseInt(jQuery(this).val().length));
}, 500));
}
This works fine. The quantity changes and if I click on the "add to cart" button, I have the quantity in my cart.
When I add this to the js code:
jQuery(".qty").attr("disabled", "disabled");
The quantity on the product detail page changes. However when I add the product to the cart, it adds always just the quantity of "1".
Does anybody know why this happens and how I can prevent this from happening? I want to disable the quantity field, because the field should be changes dynamically...
Share Improve this question asked May 28, 2022 at 15:28 TorbenTorben 2692 gold badges6 silver badges14 bronze badges1 Answer
Reset to default 1If the input is disabled, it is ignored during form submission. You can try to use readonly
attribute.
As it says in the docs: The difference between disabled
and readonly
is that read-only controls can still function and are still focusable, whereas disabled controls can not receive focus and are not submitted with the form and generally do not function as controls until they are enabled.
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly
本文标签: Change quantity via jQuery and disabile quantity field
版权声明:本文标题:Change quantity via jQuery and disabile quantity field 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738567766a2100407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论