简体   繁体   English

预定销售已结束,但在查看产品时,可变产品似乎仍在销售中 - Woocommerce

[英]Scheduled sale ended, but variable product still appears to be on sale when viewing the product - Woocommerce

Steps to recreate this issue:重现此问题的步骤:

  • create a variable product创建可变产品
  • set a sale price on a variation为变体设定销售价格
  • set a sale schedule on a variation在变体上设置销售时间表
  • wait until after the end date等到结束日期之后
  • go to frontend, view the product (or list of products), see that the sale badge and sale price are still visible转到前端,查看产品(或产品列表),看到促销徽章和促销价格仍然可见
  • add product to cart, open cart and see that price is correct (has been set back to regular)将产品添加到购物车,打开购物车并查看价格是否正确(已设置回常规)
  • if you update the product manually in wp-admin, the issue is resolved (but this really defeats the purpose of scheduled sales)如果您在 wp-admin 中手动更新产品,则问题已解决(但这确实违背了预定销售的目的)

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 中显示的价格的图像。 过期销售日期后在 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.

相关问题 获取 WooCommerce 可变产品变体的销售日期 - Get on sale dates for the variations of a WooCommerce variable product 为 Woocommerce 中正在销售的产品添加“销售”产品类别 - Adding "Sale" product category to products that are on sale in Woocommerce 自动从 Woocommerce 中的非销售产品中删除销售产品类别 - Auto remove Sale product category from not on sale products in Woocommerce 在 WooCommerce 3 中以编程方式设置产品销售价格 - Set product sale price programmatically in WooCommerce 3 在 WooCommerce 结帐问题中显示产品销售价格 - Display product sale price in WooCommerce checkout issues Woocommerce 通过正确的产品分类更改销售价格 - Woocommerce change sale price with correct product sorting 如何删除 Woocommerce 中特定产品的销售价格? - How to remove sale price on specific product in Woocommerce? 仅当产品不销售时,才将 CSS 添加到 WooCommerce 产品页面 - Add CSS to WooCommerce product pages only if product is not on sale WooCommerce单品页面上的产品销售结束倒计时 - Countdown timer until product sale ends on WooCommerce single product page 当产品的正常价格和销售价格相同时,我想在产品页面上显示可变产品的销售价格。我该怎么做? - I want to display the sale price of variable product on the product page when the regular price and sale price of product are same.How can I do this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM