- Support forum for the Min Max Default Quantity Manager for WooCommerce.
- This topic has 1 reply, 2 voices, and was last updated 5 years, 4 months ago by
Tom Anbinder.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
May 6, 2019 at 10:31 am #103998
Julien Cohignac
GuestHello, I wish to display the quantity on the product listing. So I installed the function below that works but my “value” of “quantity” can you tell me how to run the plugin with this function? Thank you in advance and good day.
/** * Add quantity field on the shop page. */ function ace_shop_page_add_quantity_field() { /** @var WC_Product $product */ $product = wc_get_product( get_the_ID() ); if ( ! $product->is_sold_individually() && 'variable' != $product->get_type() && $product->is_purchasable() ) { woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) ); } } add_action( 'woocommerce_after_shop_loop_item', 'ace_shop_page_add_quantity_field', 12 ); /** * Add required JavaScript. */ function ace_shop_page_quantity_add_to_cart_handler() { wc_enqueue_js( ' $(".woocommerce .products").on("click", ".quantity input", function() { return false; }); $(".woocommerce .products").on("change input", ".quantity .qty", function() { var add_to_cart_button = $(this).parents( ".product" ).find(".add_to_cart_button"); // For AJAX add-to-cart actions add_to_cart_button.data("quantity", $(this).val()); // For non-AJAX add-to-cart actions add_to_cart_button.attr("href", "?add-to-cart=" + add_to_cart_button.attr("data-product_id") + "&quantity=" + $(this).val()); }); // Trigger on Enter press $(".woocommerce .products").on("keypress", ".quantity .qty", function(e) { if ((e.which||e.keyCode) === 13) { $( this ).parents(".product").find(".add_to_cart_button").trigger("click"); } }); ' ); } add_action( 'init', 'ace_shop_page_quantity_add_to_cart_handler' );
-
This topic was modified 1 year, 3 months ago by
Omar Dabbas.
May 6, 2019 at 1:58 pm #103999Hi,
I will have to test this, but generally, this should get you product quantities from the plugin:
$product_id = $product->get_id(); $default = 1; $min_qty = alg_wc_pq()->core->get_product_qty_min_max( $product_id, $default, 'min' ); $max_qty = alg_wc_pq()->core->get_product_qty_min_max( $product_id, $default, 'max' ); $qty_step = alg_wc_pq()->core->get_product_qty_step( $product_id, $default );
Also – have you considered just replacing product’s add to cart form on archives with form from the single product page (in this case I believe you won’t need to add the code you’ve posted):
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 );
Please let me know if this doesn’t help.
-
This topic was modified 1 year, 3 months ago by
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.