• Resolved igeezmo

    (@igeezmo)


    I need your advice or direction in building quantity dependencies in grouped products:

    Task

    We have e-commerce website on WordPress, Woocommerce, and we are selling food boxes bundles. User can make it’s own bundle, but we want to help him make it more easy:

    There are 4 bundles with 4 boxes inside (nested products)

    User need to enter number of persons, he wants bundle for, and on front this value will be calculated with nested products dependencies, and values changes automatically in product cards.

    Example:

    John enters our website, he needs to buy bundle for 15 people, on the front he enters value “15” in field and press button.
    After that page reloads, and he see 4 presets (Meat, Vegan, Ballance, Fish). All of them are already calculated for 15 persons.
    Logic for bundle:

    Bundle 1 Master value: 15

    Box 1 (for 8 persons): calculated 15/8 and round up to closest integer value: 2 (ceil)

    Box 2 (for 5 persons): calculated 15/5 and round up to closest integer value: 3 (ceil)

    Box 3 (for 10 persons): calculated 15/10 and round up to closest integer value: 2 (ceil)

    Box 4 (for 7 persons): calculated 15/7 and round up to closest integer value: 3 (floor)

    and so on…

    User will open Bundle product with predefined values, that he could change manually as well.

    Could that be implemented with your plugin?

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @igeezmo

    No, our plugin and WooCommerce don’t work in this way. If you have created a grouped product, WooCommerce will display all grouped products into the product page, with a quantity box associated with them. Once the product is added to the cart, WooCommerce creates a new entry for every product in the group.

    The workaround would be: create with our plugin a form, with a number box for entering the number of persons, a calculated field configured as hidden to calculate the number of boxes required for every grouped product (based on your algorithm), and a calculate button.

    You can configure the equation associated with the calculated field to vary the values of quantity boxes associated to the grouped products because the “name” attribute for each of them has the format: quantity[<product's id>]

    I’ll try to describe the process with your hypothetical example. Assuming the field for the number of persons is the fieldname1, and the id of products are: 123, 456, 789 (Remember, all these values are hypothetical)

    The equation associated with the calculated field could be implemented as follows:

    
    (function(){
    var q1 = CEIL(fieldname1/8), q2 = CEIL(fieldname1/5), q3 = CEIL(fieldname1/10);
    
    jQuery('[name="quantity[123]"]').val(q1);
    jQuery('[name="quantity[456]"]').val(q2);
    jQuery('[name="quantity[789]"]').val(q3);
    })()
    

    and that’s all.
    Best regards.

    Thread Starter igeezmo

    (@igeezmo)

    Seems like that’s what I need, and where I should put this JS code?

    (function(){
    var q1 = CEIL(fieldname1/8), q2 = CEIL(fieldname1/5), q3 = CEIL(fieldname1/10);
    
    jQuery('[name="quantity[123]"]').val(q1);
    jQuery('[name="quantity[456]"]').val(q2);
    jQuery('[name="quantity[789]"]').val(q3);
    })()

    Is there any special field or in child theme functions.php?

    Thanks in advance for that fast reply, hope it will work.

    As I understood:

    jQuery('[name="quantity[123]"]').val(q1);

    This code will update quantity in nested grouped products?

    Plugin Author codepeople

    (@codepeople)

    Hello @igeezmo

    The equations are entered through the settings of calculated fields. So, the process would be implemented as follows:

    Pay attention: In the previous example, I’ve assumed the ids of grouped products are: 123, 456, and 789, but you should use the correct ids of the products on your website.

    1. Create the form as usual (just like I’ve described in the previous entry)

    2. Go to the settings page of our plugin, tick the checkbox: “CFF – WooCommerce” (it is an add-on distributed with the Developer and Platinum versions of our plugin), and press the “Activate/Deactivate Addons” button.

    3. The previous action includes a new section in the products’ settings. So, you should open the grouped product, and select the form created previously, through the attribute: “Enter the id of the form”

    More information, visiting the following post in the plugin’s blog:

    https://cff.dwbooster.com/blog/2018/11/26/woocommerce

    Best regards.

    Thread Starter igeezmo

    (@igeezmo)

    Ok, before purchasing can I contact you in slack or something?

    In your profile it says you have @codepeople account on Making WordPress group.

    Are you available there?

    I want to be sure it will work for me, I promise it will not take long.

    • This reply was modified 4 years, 3 months ago by igeezmo.
    Plugin Author codepeople

    (@codepeople)

    Hello @igeezmo

    You can contact me directly through my private website: Contact Us

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce calculated quantity in bundle’ is closed to new replies.