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
- How to correctly add Javascript in functions.php
- Edit tag cloud widget number
- How to automatically apply woocommerce product title to all product images alt tags?
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- How to get the original price of the product in woocommerce?
- Woocommerce auto cancel On-Hold after X days
- 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?
- WooCommerce – Customer Order History Pagination
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- The values of custom fields are not available functions.php
- How can I loop into two different DIVS without repeating the DIVs
- 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
- Use is_product_category() properly
- How to speed up admin-ajax.php in wordpress
- My Own layout in WooCommerce pages [closed]
- Limiting woocommerce line_total decimal length
- How do I display a user’s previous orders as a select box option on a product?
- How do you add customer capability after Woocommerce purchase?
- combine Code 1 with Code 2
- get current product name in functions.php
- Image as Sales Badge
- jQuery not defined
- Conditional Header in wordpress
- Automatically remove a canceled order in Woocommerce
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Two Different Links for Same Product – WooCommerce [closed]
- How can I apply_filters from inside a function?
- Auto-update products after they were published – Woocommerce
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- 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
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- 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
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Validation algorithm in checkout field
- My new button is in the wrong place
- How to disable controls in theme customizer?
- Function won’t run onclick using Ajax
- Theme not calling Jquery properly
- require_once() if a product in woocommerce contains a tag [closed]
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- Remove item in Checkout
- How to make jquery count down timer function manually editable
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- woocommerce specific quantities for product
- Personalize checkout text
- CSS change in woo commerce Place Order Text [closed]
- WordPress load javascript file if something… (after the page is loaded)
- Add missing alt tag to featured images for “storefront” theme
- How to call WordPress PHP file using external js file
- I was wondering if it’s possible to implement card.js on WordPress
- Find the method which AJAX GET calls
- Display text of price (minus 20%) on every product page in a sentence.
- jQuery doesn’t work in my php snippet
- Use WP_Query Data In Cookie
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- Woocommerce Price Text
- Highlight posts currently being edited on multiple editor site?
- ajax form function error
- How to get the rating value of each comment
- Add specific phrase after every product title including the discounted price? [closed]
- How to add margin underneath woocommerce total price amount -> productpages
- AJAX: WordPress filters inside $html do not work as intended
- Setting WooCommerce currency programmatically
- 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
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- posts_clauses drop ACF get_field function
- How to use js variable to php in wordpress functions.php
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- Automatically change insurance quantity based on cart total [closed]
- 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
- Woocomerce custom add to cart button edit functionality [closed]
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- Retrive the value of the Active variation of the product and then link it to the “read more” to dynamically change
- How to change product title color in shop page if product has specific product tag (Woocommerce)?
- How to capture number input from wordpress form into acf field in woocommerce
- How to add icon to WooCommerce add to cart button
- How to get default variation ID (woocommerce)