-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Price 0 / Zero / empty / php error in line 68 #5
Comments
Add fce if ($amount == 0) return 0; to line 55 to resolve my problem: joostdekeijzer#5
Hi, Add fce
to line 55 to resolve my problem. I send pool request to module improvement :) |
Hi Luka, Thanks for your report and PR. But... I'm having a hard time replicating. Is it possible the issue is in your code? I'm wondering what the output of |
Hi,
is the price of the product from woocommerce.... If the woocommerce product does not have a price (empty price) (the shop admin forgot to fill it in or has a product without a price filled in) the php error on line 58 will appear Warning: A non-numeric value encountered My pull request fixes this issue and instead of showing a php error it shows a value of 0 I use example: i add this code to: |
Hi Lukáš, I understand your PR fixes your issue but handling all kinds of unexpected input is not the correct way to develop. The In your example you best rewrite:
You can also just do and have the shortcode sort it all out 😄 |
Oops, I see that the shortcode defaults to amount=1 so that might not work for you. You'll need to validate and check the price value and act accordingly... |
it would be good to figure it out somehow, because this way of converting the woocommerce price rate is perfect. However, I don't want to show users a php error. the problem is when the price of the product is 0 or not filled in... have you not come across this usage in woocommerce? wouldn't it be a solution to apply the condition that if the value is less than 1, the result of the code will not appear at all? |
Did you test I see that with sprintf %f the output is always a float, when fed an empty string it becomes |
But I now see another issue... My plugin expects the converted amount to be With this rule the shortcode I'll want to think about how to fix this because it will change the current working and I don't want to confuse current users. |
ok, no problem :) we'll definitely figure it out somehow. |
For your current implementation I would suggest you use my longer example above, use
|
Hi,
I use your module and ran into a minor problem.
I use the conversion of euros into Czech currency and subtract the price from the price of the product using the code:
<?php $price = EuroFxRef::convert( get_post_meta( get_the_ID(), '_price', true ), 'EUR', 'CZK' ); ?> <?php echo round( $price, 0 ); ?> Kč
the problem arises with a product with a price of 0, when instead of displaying an empty value, i.e. nothing, a PHP error is displayed
Warning: A non-numeric value encountered in /data/1/d/1xyz/test.com/web/wp-content/plugins/euro-fxref-currency-converter/eurofxref.php on line 68
would it be possible to modify the logic so that the php error is displayed only to the site administrator and not to the users?
or treat the value 0 - zero so that the code does not appear at all?
Thanks
The text was updated successfully, but these errors were encountered: