WooCommerce (7 posts)

  1. nicolethompson8
    Posted 2 years ago #

    I found another post on these forums pertaining to my query but it was for the WP eCommerce plugin, not the WooCommerce plugin.


    I would like to enable decimals in my product quantities. As per the other post I amended the database from "INT" to "DECIMAL" but I'm having trouble finding the other code I need to edit in the plugin files.

    On the other post SkunkHunt mentions the following code needs replacing but I can't locate the equivalent code in the WooCommerce files, can anyone point me in the right direction?

    What you want do is change instances of (int)$_POST['quantity']; to (float)$_POST['quantity'];
    Also change instances of (int)$_POST['wpsc_quantity_update']; to (float)$_POST['wpsc_quantity_update'];
    as well as (int)$_POST['wpsc_quantity_update'][$_POST['product_id']]; to (float)$_POST['wpsc_quantity_update'][$_POST['product_id']];
  2. nicolethompson8
    Posted 2 years ago #

    OK I have actually managed to pull this off to a certain extent, by finding some similar code to the post I linked above, I changed "int" to "float" in a few places in "woocommerce-functions.php".

    This has worked, on single product pages my quantities are now in decimal form and I can type in whatever decimal I want then add it to my cart successfully. It even reflects the correct decimal quantities (and multiplied prices) when you navigate to the cart and continues to preserve the decimal quantity and correct price after you proceed to checkout....

    .... BUT, the minute you "update" the cart the decimal is lost and it returns to be a whole integer number (e.g. if my decimal was 6.9 then it returns 6 as the quantity).

    Any idea what I can now edit to preserve the decimals when the cart is updated, please?

  3. goozo
    Posted 2 years ago #

    Hi, how did u go with this, did you have any more luck? I'd also really like to implement woocommerce but their lack of decimals is the only thing holding me back. I am also a PHP dev. so I'm keen to have a hack. I haven't seen any of the code yet, is the update cart an ajax request? Is there a way to install a trial of woo commerce? Perhaps then I can have a hack too :-)

  4. wsme123
    Posted 2 years ago #

    Just wondering if there was any further development on this?

  5. msmetsers
    Posted 2 years ago #

    Need to solve this issue myself and its been driving me bonkers for a long, long time.

    Not Woocommerce but E-Commerce in my case, any help would be appreciated.


  6. evolutionsigns
    Posted 2 years ago #

    After checking the code I can see that the cart update function converts the quantity value into a positive integer using absint


    // Clean the quantity input
    $quantity = absint( $cart_totals[$cart_item_key]['qty'] );


    // DON'T Clean the quantity input
    $quantity = $cart_totals[$cart_item_key]['qty'] ;

    Should sort out the update issue.

  7. evolutionsigns
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic