I have a SQL script that is supposed to synchronize and adjust regular price comparing the text document uploaded daily on server.
New prices are written to database, and I see them when looking at database. They show in _regular_price
field properly. Problem is that frontend shows old prices .. until I manually just re-update each product in backend. Since i have thousands of products it is ineffective and tedious.
What am I missing?
Variable product prices are cached in wp_options
table as transient…
So you will need also to delete them via PhpMyAdmin with the following SQL query (for all variable products):
DELETE FROM `wp_options` WHERE `wp_options`.`option_name` LIKE '_transient_timeout_wc_var_prices_%'
DELETE FROM `wp_options` WHERE `wp_options`.`option_name` LIKE '_transient_wc_var_prices_%'
Where 1234
(at the end) is the variable product ID.
So programmatically (where $product_id
is the dynamic variable product ID):
global $wpdb;
$wpdb->query( "
DELETE FROM {$wpdb->prefix}options
WHERE {$wpdb->prefix}options.option_name LIKE '_transient_timeout_wc_var_prices_$product_id'
" );
$wpdb->query( "
DELETE FROM {$wpdb->prefix}options
WHERE {$wpdb->prefix}options.option_name LIKE '_transient_wc_var_prices_$product_id'
" );
This will remove the targeted variable product cache…
Other products (simple for example) not cached… When updating prices there is 2 cases:
_price
and _sale_price
will have the discounted product price._regular_price
will have the normal product price (non discounted)_price
and _regular_price
will have the normal product price._sale_price
will be emptySo
_price
and_regular_price
need always to be updated…