Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 计划wp_cron作业以每天更新产品元_Wordpress_Cron_Hook Woocommerce - Fatal编程技术网

Wordpress 计划wp_cron作业以每天更新产品元

Wordpress 计划wp_cron作业以每天更新产品元,wordpress,cron,hook-woocommerce,Wordpress,Cron,Hook Woocommerce,我在woocommerce产品后端中获得废品价格,这些价格我要保存在数据库中。 目前后端的价格变化,但直到我们更新产品元数据库中不更新。 如果每天更新产品,将每天在数据库中保存刮取的值。 我看到了一个如何使用wp_cron更新post的示例 但这对我已经不起作用了 这是我在theme functions.php中的代码 if( !wp_next_scheduled( 'update_products' ) ) { wp_schedule_event( time(), '

我在woocommerce产品后端中获得废品价格,这些价格我要保存在数据库中。 目前后端的价格变化,但直到我们更新产品元数据库中不更新。 如果每天更新产品,将每天在数据库中保存刮取的值。
我看到了一个如何使用wp_cron更新post的示例 但这对我已经不起作用了

这是我在theme functions.php中的代码

    if( !wp_next_scheduled( 'update_products' ) ) {  
       wp_schedule_event( time(), 'daily', 'update_products' );  
    }  

    add_action( 'update_products', 'update_product_meta' ); 

add_action( 'update_post_meta', 'update_product_meta', 10, 3 );
function update_product_meta($meta_id, $post_id, $meta_key, $meta_value) {
    global $post;
$active = array( 
    'post_type'=>'product',
    'posts_per_page'=>'-1',
    'post_status '=> 'publish',

);
$query   = new WP_Query($active);
if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
            $update =  get_the_ID();


            update_product_meta( $update );
    }
}
wp_reset_postdata();

}
请帮我设置产品的自动更新! 提前谢谢

$loop = new WP_Query(array('post_type' => array('product', 'product_variation'), 'posts_per_page' => -1, 'post_status' => 'publish'));

$count = 0; 

while ($loop->have_posts()) : $loop->the_post();
$count++;    

endwhile;

echo $count. " Products Updated Successfully";
exit;