A
A
Alexander Tokmakov2018-02-27 12:22:10
WordPress
Alexander Tokmakov, 2018-02-27 12:22:10

How to automatically update each product card?

When editing a product, there are 3 prices:
• In rubles _regular_price
• In dollars using custom fields
• In euros using custom fields
In dollars and euros, this is an additional price. Everything works like this:
1 dollar = 30r
1 euro = 50r
The course is snatched from https://www.cbr-xml-daily.ru/daily_json.js
We write the price of 1000 rubles for the product, update it, 1000r is displayed in the card.
If we now write the product in dollars, for example, 200, and update it, then the price will change to 600 and 600 will be displayed in the card. That is, the main price in rubles is updated. It is updated by querying the database.

global $wpdb;
$resuld = $wpdb->get_results("UPDATE wp_postmeta SET meta_value = $priceuroupdate2 WHERE post_id = $post_id AND meta_key = '_regular_price' ; ");
$resuld2 = $wpdb->get_results("UPDATE wp_postmeta SET meta_value = $priceuroupdate2 WHERE post_id = $post_id AND meta_key = '_price' ; ");

Everything is great.
With the euro, too, everything is fine, everything is just as well updated.
But a week later, the rate changed, but the prices do not change.
To update the prices, you need to go into the editing of each product and click on the "update" button. When goods 5-40 is not a problem. But there are 3000 products.
Please tell me how to automatically update each product card?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-03-01
@demon416nds

in the form in which you asked the question, you need to enter at least one more field in the database to
indicate which of the prices is the base

A
Alexander Sobolev, 2018-06-26
@san_jorich

jQuery to the rescue.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question