Last active
November 1, 2022 02:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.input-text.qty', 'ul.products').on('input', function() { | |
$(this).closest('li').find('.add_to_cart_button').data('quantity', $(this).val()); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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