Home › Forums › WoodMart support forum › Adding quantity to catalog page
Adding quantity to catalog page
- This topic has 1 reply, 2 voices, and was last updated 5 years, 4 months ago by Artem Temos.
-
AuthorPosts
-
July 15, 2019 at 2:49 pm #132783
evueParticipantHello,
I have added the quantity selector to the catalog using the code below. For some reason it works on the front page but not on the catalog. What would be the issue?
<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* 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’ );July 15, 2019 at 10:53 pm #132787
Artem TemosKeymasterHello,
Sorry, but since it is not an official WooCommerce solution we are not able to understand how it supposed to work and why it doesn’t work as you expected. Troubleshooting 3rd party extra customizations are out of our theme support scope.
Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register