Skip to content

Instantly share code, notes, and snippets.

@levymetal
Last active November 1, 2022 02:42
Show Gist options
  • Save levymetal/9932368 to your computer and use it in GitHub Desktop.
Save levymetal/9932368 to your computer and use it in GitHub Desktop.
How to add quantity to product archives in WooCommerce (and keep ajax). From blog post: http://christianvarga.com/how-to-add-quantity-to-product-archives-in-woocommerce-and-keep-ajax
$('.input-text.qty', 'ul.products').on('input', function() {
$(this).closest('li').find('.add_to_cart_button').data('quantity', $(this).val());
});
<?php
add_action( 'woocommerce_after_shop_loop_item', 'my_custom_quantity_field', 6 );
function my_custom_quantity_field() {
global $product;
if ( ! $product->is_sold_individually() )
woocommerce_quantity_input( array(
'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product )
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment