• Hi,
    I have a problem with orders that use COD: ue to more accurate price and tax calculations, I have set the decimal numbers in Woocommerce to 6. I then added the following function to only display 2 digits in backend and frontened:

    add_filter('wc_price_args', 'custom_decimals_price_args', 10, 1);
    function custom_decimals_price_args($args) {
        $args['decimals'] = 2;
        return $args;
    }

    But the HL plugin still places 6 digits in the COD order amount and will then not create a shippng label. Even if I manually type in an amount with only 2 decimals, I am getting the error that no label can be created because there are too many decimals…

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Shadi Manna

    (@shadim)

    You will likely have to use the filter “pr_shipping_dhl_label_args”, see example https://gist.github.com/shadimanna/b4a6ab1d4f8efcf6061cb5da3bbdb7e4.

    This is the field you need to modify and likely round to 2 decimals – $args[‘order_details’][‘cod_value’]

    Thread Starter fellter2

    (@fellter2)

    Thank you, it worked. It still displays 6 digits by default though, so only if I now manually set a two digit amount I can create a label. There is no way to automatically have the correct amount inserted (that is generated by Woo and has two decimals)?

    Plugin Author Shadi Manna

    (@shadim)

    I am not clear on what worked and what did not based on your message. Did you use the filter or not?

    Thread Starter fellter2

    (@fellter2)

    Yes, I added the following:

    add_filter('pr_shipping_dhl_label_args', 'modify_order_id_to_number', 10, 2);
    function modify_order_id_to_number($args, $order_id) {
     	$order = wc_get_order( $order_id );
    $args['order_details']['cod_value'] = 2;
    	return $args;
    }

    and this works in that now I can at least manually enter two decimals and then create a label (but the automatically entered amount by the plugin is still 6 decimals). Before aka without your function I could not even manually enter two decimals and thus not create a lable at all.

    Plugin Author Shadi Manna

    (@shadim)

    The code you added does not add decimals but the actual value of the COD required. So you need to read the order total and round it to 2 decimal points I believe.

    Thread Starter fellter2

    (@fellter2)

    Sorry, my PHP is limited…could you help me with this? In the Woo admin backend the totals are already displayed with 2 decimals (due to my function which I posted in my first post).

    Plugin Author Shadi Manna

    (@shadim)

    I would recommend you find a PHP developer to help with this customization.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problem COD order amount’ is closed to new replies.