Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 6 replies, has 2 voices.

Last updated by Andreas 1 year, 6 months ago.

Assisted by: Andreas.

Author Posts
September 14, 2022 at 9:35 pm #12054995

John

Hello,
I have just added this simple code on a PHP page on the root of WordPress with WPML install and instead of returning the value from the database is getting me a converted one (other currency).
With WCML disabled the regular_price is returning the right amount.
The id is one of the default products in the main language.

 <?php
  require_once "wp-load.php";
  global $wpdb;

$post_meta_value = get_post_meta( 9988, '_regular_price', true );

print "<pre>";
print_r($post_meta_value);
print "</pre>";
September 14, 2022 at 9:38 pm #12055043

John

output

Capture.JPG
September 15, 2022 at 10:20 am #12058201

Andreas

Hello there

Thank you for contacting us. I am happy to help you.

As far as I can see you have enabled multlcurrency mode, so the above code is normal to return the wcml price.

Now if you wish you can use WooCommerce Multlingual Hooks in order to fix the above issue you are reporting.

Please check here : https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/

I hope this helps. Please let us know how it goes or if you need any further assistance. I'll gladly help you. 🙂

Regards,
Andreas

September 15, 2022 at 10:32 am #12058429

John

Well, the problem is that I use a more complex function to retrieve the post meta value, and sometimes (random) it returns the default currency which is not okay.
I have tried to find a hook to return the current price of that product but without luck.
Some hooks are working only on the front end.
So can you please give me a solution to retrieve the default saved data in the post meta table?
Many thanks

September 15, 2022 at 11:08 am #12058771

Andreas

In order to help you can you please tell me exactly what you are trying to achieve?

For example, you can use REST API in order to get the price from a product, without involving actions and filters that may run in the middle of your request.

You can read more here :
hidden link

and here :
https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual/

Can you please check?

Thank you

Regards,
Andreas

September 15, 2022 at 11:13 am #12058815

John

Sure,
Many thanks for your suggestion.
Yes, simply I'm trying to get the default currency for the products based on the ID.
There is a hook for that but like I said only works on the front end. I was looking for something to suppress this price modification by WCML.
Regarding rest API seems to be the only way to achieve this, even if all the data are on the same installation...it's kind of strange to use rest API when you have all the data in the same place.
Are you 100% there is no hook to bypass this? And get the correct value by post meta? Thanks

September 15, 2022 at 12:27 pm #12059833

Andreas

Thank you very much for the reply.

We are having many ajax requests in the frontend and adjusting them in order to get the price from the database it is not the optimum way. This is why I suggest rest api which in general, not this implementation, can save you time and speed.

If you insist to use hooks, the only way I can think is to use this hook :

https://wpml.org/wcml-hook/wcml_product_price_by_currency/

You know the product ID, you know the default currency, so you can get for the product the price in default currency.

Again maybe this is not fit in your implementation, you can check all the hooks you are having and maybe you can find other combinations that might work for you.

https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/

I hope this helps you but I think you can make it work this way. If you have further questions please do not hesitate to ask.

Regards,
Andreas

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.