• Resolved msaidefe

    (@msaidefe)


    Hello,

    First of all, I’d like to express my gratitude for creating such a useful plugin. However, I seem to have encountered a slight issue which I believe requires your expertise.

    I’m currently using the shortcode [convert number=50 from=”usd” to=”try”] within a different Woocommerce plugin. Under normal circumstances, this shortcode efficiently converts the American Dollar to the target currency and displays the result correctly. However, when attempting to use this shortcode within a different Woocommerce plugin, I’m facing an unexpected error when the total price of the product surpasses 1000 Turkish Liras.

    The problem lies in the fact that when the value exceeds 1000 Turkish Liras, the conversion result is displayed as either 1 or another nonsensical number. In order to diagnose the underlying cause of this behavior, I’ve taken various steps. For instance, I’ve tried downgrading the PHP version from 8.0 to 7.4, but the issue persists.

    I kindly request your assistance in shedding light on the mechanism behind the conversion process within your plugin and explaining potential scenarios that could lead to such a conversion error for values above 1000. Additionally, any suggestions you may have for resolving this issue would be greatly appreciated.

    To provide a better understanding of my problem, I’m including an example of the shortcode I’m attempting to use:

    [convert number=50 from="usd" to="try"]

    I eagerly await your guidance on this matter. Thank you in advance for your help.

    Best regards,

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor David Artiss

    (@dartiss)

    If I try your example on my own site, it works just fine.

    You say it only seems to occur “when attempting to use this shortcode within a different Woocommerce plugin”, which I’m assuming is relevant here. Can you please provide further details about this?

    Thread Starter msaidefe

    (@msaidefe)

    I apologize for not providing a fully detailed explanation earlier, and I’d like to show you a live example now.

    Click

    The link I’ve left above directs you to a testing environment. The calculations are based on the values entered in the ‘Height (cm)’ section of this product. It displays accurate results for values entered between 60 and 200 because the total is still below 1000 Turkish Liras. However, when values are entered between 201 and 350, I’m not obtaining the desired results. This is because the converted Turkish Lira value of the dollar amount I’m calculating is now exceeding 1000 TRY.

    To elaborate further, the calculations are correct up to a height of 200 cm, but for values beyond that range, the results become nonsensical.

    Initially, I suspected the issue was related to the Extra Product Options plugin I’m using in that area. However, it seems that’s not the case. I’ve tested with other currency conversion plugins, and they don’t encounter this calculation problem either. They also don’t work for me because they can’t calculate the total in the cart. Your provided plugin is perfect for my needs. However, due to this unresolved issue, I’m unable to achieve what I intend.

    How can we resolve this situation? Thank you for your attention.

    Plugin Contributor David Artiss

    (@dartiss)

    Thanks for the example. Looking at the example, I’m assuming you’re not using the shortcode but are calling the function directly? If so, can you provide the code that you’re using for this?

    Thread Starter msaidefe

    (@msaidefe)

    Hi,

    I’m using the shortcode directly within the ‘Extra Product Options & Add-Ons for WooCommerce’ plugin, as this plugin allows shortcode usage.

    The code I’m using within the ‘Height (Cm)’ input is structured as follows:

    if(({this.value} >= 60) && ({this.value} <= 100), [convert number=25 from="usd" to="try"]+{product_price}, if(({this.value} >= 101) && ({this.value} <= 150), [convert number=30 from="usd" to="try"]+{product_price}, if(({this.value} >= 151) && ({this.value} <= 200), [convert number=34 from="usd" to="try"]+{product_price}, if(({this.value} >= 201) && ({this.value} <= 250), [convert number=38 from="usd" to="try"]+{product_price}, if(({this.value} >= 251) && ({this.value} <= 310), [convert number=42 from="usd" to="try"]+{product_price}, if(({this.value} >= 311) && ({this.value} <= 350), [convert number=46 from="usd" to="try"]+{product_price}, {product_price}))))))

    This code block works well until the [convert number=34 from=”usd” to=”try”] step. The result stays below the value of 1000. For instance, 34 dollars convert to 924 Turkish Liras.

    However, once we move to the [convert number=38 from=”usd” to=”try”] step, 38 dollars convert to 1033 Turkish Liras. This is when the issue begins as the value exceeds 1000. Feel free to test it yourself.

    If you’d like, I can also provide administrator credentials to your email address.

    Thank you for your attention.

    • This reply was modified 1 year, 3 months ago by msaidefe.
    • This reply was modified 1 year, 3 months ago by msaidefe.
    Plugin Contributor David Artiss

    (@dartiss)

    If you’d like, I can also provide administrator credentials to your email address.

    No thank you and please don’t offer these – it’s not good practise to offer up site access like this to people you don’t know (and the mods here will take a dim view of it!).

    Looking at the code you provided, I’m curious about this bit…

    [convert number=25 from="usd" to="try"]+{product_price}

    Does this mean that the product price is being added to the converted currency?

    Thread Starter msaidefe

    (@msaidefe)

    No thank you and please don’t offer these – it’s not good practise to offer up site access like this to people you don’t know (and the mods here will take a dim view of it!).

    Thank you for the warning; you being the developer of the plugin I’m interested in, I suppose I can trust you ?? Moreover, the information I’m going to send is for a test environment anyway ?? Still, I appreciate your kind reminder.

    Does this mean that the product price is being added to the converted currency?

    Yes, that’s absolutely right.

    Plugin Contributor David Artiss

    (@dartiss)

    Okay, so it looks like that plugin is to blame here. It’s taking the output from my plugin, adding something additional and the output is coming out wrong. My suggestion here would be to reach out to the developer of the other plugin to see if they can understand why. Because it’s over 1000 it may be because it doesn’t like the thousands separator in it (e.g. 1,000 rather than 1000).

    Plugin Contributor David Artiss

    (@dartiss)

    How did you get on with this?

    Thread Starter msaidefe

    (@msaidefe)

    How did you get on with this?

    I apologize for the delayed response.

    The issue was indeed related to the thousands separator, as you mentioned. Since I didn’t want to spend too much time contacting the other plugin author, I decided to try my luck by making a minor modification to your plugin, and it worked. The change I made was as follows:

    In ‘artiss-currency-converter/includes/convert-currency.php’:

    Line 137:

    $result = number_format( round( $number * ( $to * ( 1 / $from ) ), $dp ), $dp, '.', ',' ); // The trailing comma was removed 

    After making this change, I achieved the desired result. You might consider updating the plugin in this manner. Nevertheless, I want to express my gratitude once again for your assistance.

    • This reply was modified 1 year, 2 months ago by msaidefe.
    Plugin Contributor David Artiss

    (@dartiss)

    Thanks – I’m glad you got it fixed.

    Yes, there’s already an open request to make the thousands separator customisable

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Currency Conversion Issue in Woocommerce: Conversion Error for Values Above 1000’ is closed to new replies.