Is there a way or a plugin to reset quantity input field every time a user changes the variation? I searched but i didn't find something similar or any hook.
I tried the following jQuery event but it doesn't seem to fire
function variation_select_change() {
global $woocommerce;
?>
<script>
jQuery(function($){
$( ".variations_form" ).on( "woocommerce_variation_select_change", function () {
alert( "Options changed" );
} )
});
</script>
Is there a way or a plugin to reset quantity input field every time a user changes the variation? I searched but i didn't find something similar or any hook.
I tried the following jQuery event but it doesn't seem to fire
function variation_select_change() {
global $woocommerce;
?>
<script>
jQuery(function($){
$( ".variations_form" ).on( "woocommerce_variation_select_change", function () {
alert( "Options changed" );
} )
});
</script>
Share
Improve this question
edited Oct 14, 2019 at 14:55
Billy
asked Oct 14, 2019 at 14:40
BillyBilly
573 silver badges13 bronze badges
1 Answer
Reset to default 1To reset quantity input field to 1 when variation changes on product detail page use below code. you can set default quantity from jQuery("[name='quantity']").val(1);
. i have tested and it is working fine for me.
add_action( 'wp_footer', 'variation_change_update_qty' );
function variation_change_update_qty() {
if (is_product()) {
?>
<script>
jQuery(function($){
$( ".variations_form" ).on( "woocommerce_variation_select_change", function () {
jQuery("[name='quantity']").val(1);
} )
});
</script>
<?php
}
}
let me know is this works for you!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745075764a4609825.html
评论列表(0条)