• Resolved m3g4tr

    (@m3g4tr)


    Hey everyone,

    I made a custom quantity input (x1, x3 and x3) that looks something like this: https://imgur.com/a/sVMDTMk

    I achieved this using Javascript to modify the value of the input provided below:

    <input type="number" id="quantity_61b90a7cab27c" class="input-text qty text" step="1" min="1" max="10" name="quantity" value="1" title="Količina" size="4" placeholder="" inputmode="numeric">

    When a user clicks on either x1, x3 or x3 I update the value accordingly.

    Now I have an issue with variations. I use Javascript to append multiple variation inputs to the DOM but the issue is that the back-end doesn’t know how to process multiple variations when adding the specified quantity of products to the cart.

    My question: How can I modify the back-end logic to actually add different variations of the specified quantity (e.g when a user selects x3 he can choose 2 red T-shirts and one blue T-shirt)

    When I inspected the code of some other Woocommerce websites that do this I noticed that they generate multiple variation inputs and change value (that is sent using the from a single value to array, like this:

    – Single value
    <select id="choose-color" class="" name="attribute_choose-color" data-attribute_name="attribute_choose-color" data-show_option_none="yes"><option value="">Choose color</option><option value="Blue" class="attached enabled">Blue</option><option value="Red" class="attached enabled">Red</option></select>
    – Variations name="attribute_choose-color[1], name="attribute_choose-color[2] and so on.. but my endpoint is not prepared for it and I get and error

    
    Warning: preg_match() expects parameter 2 to be string, array given in /home/customer/www/megatrgovina.si/public_html/wp-includes/formatting.php on line 1586
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @m3g4tr!

    Since this requires custom coding, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For additional assistance on this topic, we recommend getting in touch with one of the customization experts listed on the WooCommerce Customizations Page.

    Also, you can visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack, you could find help from the community of open-source developers for WooCommerce that hangs in there.

    Cheers!

    Hi there 👋

    We haven’t heard back from you in a while. Hopefully, you found a solution to your case. I am marking this thread as resolved now. If you have further questions, I recommend creating a new one.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom variation input’ is closed to new replies.