php - WooCommerce - Reset quantity input field when variation changes

Is there a way or a plugin to reset quantity input field every time a user changes the variation? I searched but i didn&

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
Add a comment  | 

1 Answer 1

Reset to default 1

To 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

相关推荐

  • php - WooCommerce - Reset quantity input field when variation changes

    Is there a way or a plugin to reset quantity input field every time a user changes the variation? I searched but i didn&

    13小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信