-
AuthorPosts
-
November 26, 2020 at 12:23 pm #1263239
I have added the option to specify the number of items directly on the product overview in a shop. I found this function in another support post at Enfold.
Unfortunately, however, if e.g. 6 products can be added to the shopping cart using the function – actually only 1 product added.
Can you help me solve the problem?See Pic added in private content.
Thanks for helping me!
November 26, 2020 at 7:38 pm #1263342Hey awasner,
Could you please give us a link to your website, we need more context to be able to help you.
Best regards,
VictoriaNovember 30, 2020 at 11:55 pm #1264076Hey Victoria,
attached you`ll find the link to the site.
Thanks for helping me!
December 3, 2020 at 1:11 pm #1264754Hi,
I found this function in another support post at Enfold.
Which function did you add, and where did you get it? Please provide the link to the previous thread so that we could test the snippet. We might have to adjust the initial value of the data-quantity attribute to make this work properly.
Best regards,
IsmaelDecember 3, 2020 at 1:14 pm #1264755I added the following code:
/**
* Add quantity field on the archive page.
*/
function custom_quantity_field_archive() {$product = wc_get_product( get_the_ID() );
if ( ! $product->is_sold_individually() && ‘variable’ != $product->product_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’, ‘custom_quantity_field_archive’, 0, 9 );/**
* Add requires JavaScript.
*/
function custom_add_to_cart_quantity_handler() {wc_enqueue_js( ‘
jQuery( “.type-product” ).on( “click”, “.quantity input”, function() {
return false;
});
jQuery( “.type-product” ).on( “change input”, “.quantity .qty”, function() {
var add_to_cart_button = jQuery( this ).parents( “.product” ).find( “.add_to_cart_button” );// For AJAX add-to-cart actions
add_to_cart_button.data( “quantity”, jQuery( 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=” + jQuery( this ).val() );
});
‘ );}
add_action( ‘init’, ‘custom_add_to_cart_quantity_handler’ );/*Remove Flag form Enfold Menu*/
function avia_remove_main_menu_flags(){
remove_filter( ‘wp_nav_menu_items’, ‘avia_append_lang_flags’, 9998, 2 );
remove_filter( ‘avf_fallback_menu_items’, ‘avia_append_lang_flags’, 9998, 2 );
remove_action( ‘avia_meta_header’, ‘avia_wpml_language_switch’, 10);
}
add_action(‘after_setup_theme’,’avia_remove_main_menu_flags’);—
I think somewhere from this site… i added it a while ago,- but noticed it later that it don`t worked
https://kriesi.at/support/topic/adding-quantity-field-in-shop-overview-page-woocommerce/
https://kriesi.at/support/topic/add-a-quantity-field-to-woocommerce-products/December 7, 2020 at 5:22 am #1265389Hi,
Thank you for the update.
How did you set the initial value to 6? We might have to adjust the value of the data-quantity attribute of the add_to_cart_button button or element on page load.
Something like this..jQuery(document).ready(function() { var add_to_cart_button = jQuery( ".add_to_cart_button" ); add_to_cart_button.data( "quantity", 6 ); });
Best regards,
IsmaelDecember 7, 2020 at 9:53 am #1265425Dear Ismael,
do i just add this code to the existing?
initial value to 6 –> i just found this code on enfold support and used it… no idea how it really works ;-)Best Regards,
AndreasDecember 8, 2020 at 12:30 pm #1265736Hi,
Thank you for following up.
Try to replace the custom_add_to_cart_quantity_handler function and associated inithook with the following snippet.
/** * Add requires JavaScript. */ function ava_custom_add_to_cart_quantity_handler() { wc_enqueue_js( ' (function($) { // set initial value to 6 $(document).ready(function() { var add_to_cart_button = $( ".add_to_cart_button" ); add_to_cart_button.data( "quantity", 6 ); }); $( ".type-product" ).on( "click", ".quantity input", function() { return false; }); $( ".type-product" ).on( "change input", ".quantity .qty", function() { var add_to_cart_button = jQuery( this ).parents( ".product" ).find( ".add_to_cart_button" ); // For AJAX add-to-cart actions add_to_cart_button.data( "quantity", jQuery( 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=" + jQuery( this ).val() ); }); })(jQuery); ' ); } add_action( 'init', 'ava_custom_add_to_cart_quantity_handler' );
Best regards,
IsmaelDecember 10, 2020 at 5:32 pm #1266333Hey Ismael,
same like before. I have deleted the code in the meantime, because customers try to order different quantities of bottles through this quantitiy field, but only 1 goes in the cart.
Do you have another idea?
Best Regards,
AndreasDecember 13, 2020 at 12:06 am #1266812 -
AuthorPosts
- You must be logged in to reply to this topic.