Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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!

    #1263342

    Hey awasner,

    Could you please give us a link to your website, we need more context to be able to help you.

    Best regards,
    Victoria

    #1264076

    Hey Victoria,

    attached you`ll find the link to the site.

    Thanks for helping me!

    #1264754

    Hi,

    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,
    Ismael

    #1264755

    I 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/

    #1265389

    Hi,

    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,
    Ismael

    #1265425

    Dear 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,
    Andreas

    #1265736

    Hi,

    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,
    Ismael

    #1266333

    Hey 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,
    Andreas

    #1266812

    Hi,

    Would you mind if we access the dashboard and the file server? We have to be able to edit the above script in order to properly test it. Please post the WP and FTP details in the private field.

    Thank you for your patience.

    Best regards,
    Ismael

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.