Woocommerce-自动补货产品 [英] Woocommerce - Automatic restock a product
本文介绍了Woocommerce-自动补货产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在商店中使用wordpress和woocommerce.
I'm using wordpress and woocommerce for my shop.
我每天晚上都需要补货.
I need to restock a product every night.
例如我有一个库存量为30的产品. 那么,如果有人购买了该产品,则金额为29-当然. 但是第二天,股票应该会自动再次切换到30.
Ex. I have a product where the stock amount is 30. Then if someone buys the product the amount is 29 - of course. But then the next day, the stock should automatically switch to 30 again.
有人知道怎么做吗?还是创建php/code/function之类的东西?
Does anyone know how to do that? Or create a php/code/function or something?
推荐答案
注册一个名为increase_stock_daily
的cron事件,并使其每天或根据您的要求运行.
Register a cron event named increase_stock_daily
and have it run daily or as per your requirement.
// Add function to register event to WordPress init
add_action( 'init', 'register_daily_stock_event');
// Function which will register the event
function register_daily_stock_event() {
// Make sure this event hasn't been scheduled
if( !wp_next_scheduled( 'increase_stock_daily' ) ) {
// Schedule the event
wp_schedule_event( time(), 'daily', 'increase_stock_daily' );
}
}
function increase_stock_daily() {
$product = new WC_Product(10); // replace 10 with your own product ID
if($product->get_total_stock() < 30) {
$product->set_stock(30);
}
}
这篇关于Woocommerce-自动补货产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文