admin管理员组文章数量:1318032
I need to update all prices in my store to end in .99, both on the front end and in the database. I have the following code which appears to do it when I run a shortcode, but I have a problem.
When I look at the products in the admin they sill show the old prices. I've cleared the transients and regenerated the product lookup tables but the old prices are still showing, which makes me think the new prices are only shown on the front end, even though the code is clearly updating the database. Bit confused.
add_shortcode( 'shortcode_update_price','shortcode_update_price' );
function shortcode_update_price(){
global $wpdb;
$prefix = $wpdb->prefix;
$results = $wpdb->get_results( "SELECT `meta_id`, `meta_value` FROM {$prefix}postmeta WHERE `meta_key`='_price'", ARRAY_A );
if ( !empty($results) ) {
foreach ($results as $key => $value) {
$new_price = ceil($value['meta_value']) - 0.01;
$wpdb->query( "UPDATE {$prefix}postmeta SET `meta_value`=$new_price WHERE `meta_id`=$value[meta_id]" );
}
}
}
What am I doing wrong? Is this likely still just a caching issue?
I need to update all prices in my store to end in .99, both on the front end and in the database. I have the following code which appears to do it when I run a shortcode, but I have a problem.
When I look at the products in the admin they sill show the old prices. I've cleared the transients and regenerated the product lookup tables but the old prices are still showing, which makes me think the new prices are only shown on the front end, even though the code is clearly updating the database. Bit confused.
add_shortcode( 'shortcode_update_price','shortcode_update_price' );
function shortcode_update_price(){
global $wpdb;
$prefix = $wpdb->prefix;
$results = $wpdb->get_results( "SELECT `meta_id`, `meta_value` FROM {$prefix}postmeta WHERE `meta_key`='_price'", ARRAY_A );
if ( !empty($results) ) {
foreach ($results as $key => $value) {
$new_price = ceil($value['meta_value']) - 0.01;
$wpdb->query( "UPDATE {$prefix}postmeta SET `meta_value`=$new_price WHERE `meta_id`=$value[meta_id]" );
}
}
}
What am I doing wrong? Is this likely still just a caching issue?
Share Improve this question asked Oct 31, 2020 at 12:57 XavXav 3991 gold badge9 silver badges23 bronze badges1 Answer
Reset to default 0You should try to use _regular_price
meta key in your SQL query.
Regular price from the admin use the value of _regular_price
key while the price shown at the frontend use the value of _price
key. Keep in mind that _price
is the active price of the product, if the product is currently on sale then the _price
will use the value of _sale_price
. The value of _price
will be updated daily by default WC hook cron.
本文标签: cacheWoocommercehow to round up all prices to end in 99
版权声明:本文标题:cache - Woocommerce - how to round up all prices to end in .99 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742023454a2415108.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论