• Resolved izquierdocreativo

    (@izquierdocreativo)


    Hi, your plugin is wonderful, but I see a detail that does not allow me to work 100% with it. I hope you can help me with some new update or snippet.
    It does not show me the fractional units. It puts the whole number and modifies the unit price, but that is not valid for an invoice. The unit for example is 9.5 and it says 9. The unit price is 30 and it says 31.67. This is not valid.
    Could you solve it please?
    Thank you very much.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @izquierdocreativo,

    Could you please show me a screenshot of the details from a test order, and its PDF invoice? You can use imgbb.com to upload the images, and then share their URLs here.

    To clarify, this is the order details I refer to:

    A screenshot of the order details from a test order

    Thread Starter izquierdocreativo

    (@izquierdocreativo)

    The problem from what I see is that woocommerce does not respect the purchase of fractional products and has done what it wanted. The invoice plugin respects what woo says.
    Sorry for the inconvenience and thank you very much for your reply.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    You’re right. This is the default behavior from WooCommerce. However, some plugins enables the decimals in the quantity field.

    If you need to allow this in your store by yourself, without any plugin, you could use this code snippet, that seems to be working yet:

    // Add min value to the quantity field (default = 1)
    add_filter('woocommerce_quantity_input_min', 'min_decimal');
    function min_decimal($val) {
        return 0.1;
    }
     
    // Add step value to the quantity field (default = 1)
    add_filter('woocommerce_quantity_input_step', 'nsk_allow_decimal');
    function nsk_allow_decimal($val) {
        return 0.1;
    }
     
    // Removes the WooCommerce filter, that is validating the quantity to be an int
    remove_filter('woocommerce_stock_amount', 'intval');
     
    // Add a filter, that validates the quantity to be a float
    add_filter('woocommerce_stock_amount', 'floatval');
     
    // Add unit price fix when showing the unit price on processed orders
    add_filter('woocommerce_order_amount_item_total', 'unit_price_fix', 10, 5);
    function unit_price_fix($price, $order, $item, $inc_tax = false, $round = true) {
        $qty = (!empty($item['qty']) && $item['qty'] != 0) ? $item['qty'] : 1;
        if($inc_tax) {
            $price = ($item['line_total'] + $item['line_tax']) / $qty;
        } else {
            $price = $item['line_total'] / $qty;
        }
        $price = $round ? round( $price, 2 ) : $price;
        return $price;
    }

    Source: https://codeontrack.com/use-decimal-in-quantity-fields-in-woocommerce-wordpress/

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Hope it helps!

    Thread Starter izquierdocreativo

    (@izquierdocreativo)

    Thank you very much!!!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    We’re happy to help!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘error units in invoice’ is closed to new replies.