在 Woocommerce 中使用 SQL 查询更新产品价格缓存问题 [英] Updating product prices cache issue using a SQL query in Woocommerce
问题描述
我有一个 SQL 脚本,用于同步和调整正常价格,比较每天上传到服务器上的文本文档.
I have a SQL script that is supposed to synchronize and adjust regular price comparing the text document uploaded daily on server.
新价格写入数据库,我在查看数据库时看到它们.它们正确显示在 _regular_price
字段中.问题是前端显示旧价格......直到我手动重新更新后端的每个产品.由于我有数千种产品,因此效率低下且乏味.
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.
我错过了什么?
推荐答案
可变产品价格被缓存在 wp_options
表中作为瞬态...
Variable product prices are cached in wp_options
table as transient…
因此,您还需要使用 SQL 删除每个变量产品 ID,如下所示:
So you will need also to delete through SQL using for each variable product ID something like this:
DELETE FROM `wp_options` WHERE `wp_options`.`option_name` LIKE '_transient_timeout_wc_var_prices_1234'
DELETE FROM `wp_options` WHERE `wp_options`.`option_name` LIKE '_transient_wc_var_prices_1234'
其中 1234
(在末尾)是可变产品 ID.
Where 1234
(at the end) is the variable product ID.
因此以编程方式(其中 $product_id
是动态变量产品 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:
1) 产品在售:
_price
和_sale_price
将具有折扣产品价格._regular_price
将具有正常的产品价格(非折扣)
_price
and_sale_price
will have the discounted product price._regular_price
will have the normal product price (non discounted)
2) 该产品不打折:
_price
和_regular_price
将具有正常的产品价格._sale_price
将为空
_price
and_regular_price
will have the normal product price._sale_price
will be empty
所以_price
和_regular_price
需要一直更新......
So
_price
and_regular_price
need always to be updated…
这篇关于在 Woocommerce 中使用 SQL 查询更新产品价格缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!