使用cron更新库存数量wocoommerce Daily

问题描述

我想每天更新woocommerce产品的库存。每天输入的数量由每个产品中的acf字段给出。

产品是可变的,但是它们都只有一个变体,因此仅在产品的常规选项卡中设置库存。因此,库存是独一无二的。

这是我的代码,但是更新功能返回false给我,而每种产品的日库存量正确显示

function tommix_custom_cron_schedule_two($schedules) {
    if (!isset($schedules["tommix_daily"]))
        $schedules["tommix_daily"] = array(
            'interval' => 86400,'display'  => __('Daily'),);
    return $schedules;
}
add_filter('cron_schedules','tommix_custom_cron_schedule_two');

if (!wp_next_scheduled('wp_footer')) {
    wp_schedule_event(time(),'tommix_daily','wp_footer');
}

add_action('wp_footer','tommix_cron_function');

function tommix_cron_function($post_id) {
    $daily_stock = get_field('al_giorno',$post_id);
    if (!empty($daily_stock)) {
        d($daily_stock);
        //update_post_Meta($post_id,"_stock",$daily_stock);
        d(update_post_Meta($post_id,$daily_stock));
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)