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!
Related Posts:
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How can I get the values of my WordPress $wpdb query in Jquery?
- Execute PHP code only with specific user role
- Woocommerce – if selected attribute term equals
- Replace the image of a product with its video in the shop page
- Edit tag cloud widget number
- How to get the original price of the product in woocommerce?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- How to use WordPress (PHP) functions in AngularJS partials files?
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Remove commas from WooCommerce checkout addresses fields
- WooCommerce – Display variation custom field value [closed]
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- Woocommerce HTML email option unavailable
- Click loads template via ajax
- How to add SVG icon above product tab title
- How to speed up admin-ajax.php in wordpress
- My Own layout in WooCommerce pages [closed]
- Woocommerce – remove product from category
- Limiting woocommerce line_total decimal length
- How do you add customer capability after Woocommerce purchase?
- get current product name in functions.php
- Image as Sales Badge
- jQuery not defined
- Automatically remove a canceled order in Woocommerce
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- How can I apply_filters from inside a function?
- Auto-update products after they were published – Woocommerce
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- dynamic dependent select dropdown
- Change “add to cart” button color based on Woocommerce product category [closed]
- Ajax load more button for comments wordpress
- My new button is in the wrong place
- How to disable controls in theme customizer?
- Function won’t run onclick using Ajax
- require_once() if a product in woocommerce contains a tag [closed]
- Remove item in Checkout
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Personalize checkout text
- CSS change in woo commerce Place Order Text [closed]
- Why i can’t get custom fields value or post ID via Ajax?
- WP All Import / Update stock quantity from multiple XML files
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- How do i wrap woocomerce attribute in list?
- Removing files programmatically
- Custom Taxonomy Select Menu: Setting default option value?
- Execute Jquery when a specific page in my plugin is loading
- How to set value selected using select2 jquery plugin
- Woocommerce order status payment
- Modify WooCommerce used to get all orders in dashboard
- Database entry removed on browser refresh, Ajax PHP jQuery
- Woocommerce My acount page
- Woocommerce – Exclude variation attribute on specific variation
- Display custom field value in woocommerce variable product via jQurey
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- PHP function for horizontal Woocommerce thumbnails and badges
- Ajax filter with loadmore button
- php code for outputting a custom page in my account
- Hide specific shipping methode depending on day and time of day
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- Adding custom field to product category and show it to shop/category shop page
- Hide payment method based on user role AND minimum cart value
- WooCommerce display price before add to cart [closed]
- Remove span tags from WooCommerce Downloads page
- Customize the “Available for back order” text for specific variation
- Update $wpdb query with AJAX
- Discount in the specific product title using keyword ( Woocoommerce )
- Including user data in “new user notification email”
- AJAX to add to cart multiple products woocommerce
- Add Product Permalink in woocommerce admin order page
- JQuery modal not loading video on popup, only displaying it after multiple reopenings
- Woocommerce textarea format ignored
- How to auto-generate random numbers in username?
- Remove generated category and tag class names from woocommerce product & blog listings markup
- WP_Query To Display Product Of Brand On Taxonomy Page
- Woocommerce Add custom “Add to cart button” in single page with tags
- How to echo a PHP code into WooCommerce variation product?
- Get Billing Email from WooCommece Checkout and Pass to Fullstory JS
- How to call a function from functions.php with ajax?
- WordPress load javascript file if something… (after the page is loaded)
- Add missing alt tag to featured images for “storefront” theme
- I was wondering if it’s possible to implement card.js on WordPress
- Find the method which AJAX GET calls
- Woocommerce Price Text
- ajax form function error
- How to get the rating value of each comment
- How to add margin underneath woocommerce total price amount -> productpages
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- Warning: Attempt to read property “term_id” on int – Woocommerce
- How to use js variable to php in wordpress functions.php
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- How call WordPress shortcode inside function file
- strict custom php script on specific product category [closed]
- Change WooCommerce Order status from frontend form submitted data
- Add text below WooCommerce short description if metabox value is true