[英]Scheduled sale ended, but variable product still appears to be on sale when viewing the product - Woocommerce
Steps to recreate this issue:重现此问题的步骤:
I am using Woocommerce v2.6.14 and Wordpress v4.7.6.我正在使用 Woocommerce v2.6.14 和 Wordpress v4.7.6。
If I try to check $product->is_in_stock()
on product view, I get 1
(not correct).如果我尝试在产品视图上检查$product->is_in_stock()
,我得到1
(不正确)。 If I add this product to cart and check this same thing, I get 0
(correct).如果我将此产品添加到购物车并检查相同的内容,我会得到0
(正确)。
So, the issue is that the variation price doesn't automatically update after sale end date .因此,问题是在销售结束日期之后,变动价格不会自动更新。
I would really appreciate every advice!我真的很感激每一个建议! :) Thank you! :) 谢谢!
Additional info:附加信息:
This is an image of displayed price in wp-admin after expired sale date on one product.这是一个产品的销售日期过期后在 wp-admin 中显示的价格的图像。
Sale price is still saved in the WC Variable object before it is added to cart.销售价格在添加到购物车之前仍保存在 WC Variable 对象中。 After a product is added to cart, min and max variation sale price is the same as regular price and everything works correctly.将产品添加到购物车后,最小和最大变化销售价格与正常价格相同,并且一切正常。
If I use $product->get_price_html();
如果我使用$product->get_price_html();
I get wrong value before add to cart action, and if I use $product->get_price();
在添加到购物车操作之前我得到了错误的值,如果我使用$product->get_price();
I get the correct value.我得到正确的值。
UPDATE: After I changed the WC version to 2.7.0 RC 1, the prices went back to correct ones, but updating WC messed up a lot of other things, so updating is not an option.更新:在我将 WC 版本更改为 2.7.0 RC 1 后,价格又回到了正确的价格,但更新 WC 会搞砸很多其他事情,因此更新不是一种选择。 Something just isn't updating correctly when the scheduled sale ends and I can't figure out what.当预定的销售结束时,有些东西没有正确更新,我不知道是什么。
The woocommerce_scheduled_sales
event is what triggers the actual pricing changes to the products with scheduled sales.This event should be run once a day but maybe this does not happen. woocommerce_scheduled_sales
事件触发了具有预定销售的产品的实际价格变化。这个事件应该每天运行一次,但也许这不会发生。 to find sites WP Cron events you can use the below plugin :要查找站点 WP Cron 事件,您可以使用以下插件:
https://wordpress.org/plugins/wp-crontrol/ https://wordpress.org/plugins/wp-crontrol/
by this plugin you can immediately run any cron events.you should find woocommerce_scheduled_sales
and run it.通过此插件,您可以立即运行任何 cron 事件。您应该找到woocommerce_scheduled_sales
并运行它。
also you can use this code in your function theme to run event every Six hours.您也可以在函数主题中使用此代码每六小时运行一次事件。
<?php
function myprefix_custom_cron_schedule( $schedules ) {
$schedules['every_six_hours'] = array(
'interval' => 21600, // Every 6 hours
'display' => __( 'Every 6 hours' ),
);
return $schedules;
}
add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' );
//Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_wc_scheduled_sales' ) ) {
wp_schedule_event( time(), 'every_six_hours', 'myprefix_wc_scheduled_sales' );
}
///Hook into that action that'll fire every six hours
add_action( 'myprefix_wc_scheduled_sales', 'myprefix_run_wc_scheduled_sales' );
//create your function, that runs on cron
function myprefix_run_wc_scheduled_sales() {
//your function...
wc_scheduled_sales();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.