【发布时间】:2021-04-07 21:26:35
【问题描述】:
基于 Automatically cancel order after X days if no payment in WooCommerce 答案代码,我做了一些更改,试图在 x 分钟 (或 x 小时)后自动完成已付款订单:
add_action( 'woocommerce_order_status_changed', 'hourly_update_status_orders', 10, 4 );
function hourly_update_status_orders( $order_id, $old_status, $new_status, $order ) {
// Set Your shop time zone (http://php.net/manual/en/timezones.php)
date_default_timezone_set('Europe/London');
// Enable the process to be executed daily
if( in_array( $new_status, array('processing') )
&& get_option( 'paid_orders_hourly_process' ) < time() ) :
$time_delay = 60 * 5; // <=== SET the time delay (here 1 hour)
$current_time = strtotime(str_replace(':','-', date('Y-m-d h:i:s') ));
$targeted_time = $current_time - $time_delay;
// Get paid orders (10 mints old)
$paid_orders = (array) wc_get_orders( array(
'limit' => -1,
'status' => 'processing',
'date_created' => '<' . $targeted_time,
'return' => 'ids',
) );
if ( sizeof($paid_orders) > 0 ) {
$completed_text = __("The order is Completed.", "woocommerce");
// Loop through WC_Order Objects
foreach ( $paid_orders as $paid_order ) {
$order->update_status( 'completed', $complted_text );
}
}
// Schedule the process to the next day (executed once restriction)
update_option( 'paid_orders_hourly_process', $current_time + $time_delay );
endif;
}
我只能让它适用于每天的变化,但不能适用于每小时的变化......
谁能帮我检查一下我哪里错了?
【问题讨论】:
-
我删除了processing 标签。 Processing 是一个灵活的软件速写本,也是一种学习如何在视觉艺术环境中编码的语言。
标签: php wordpress woocommerce scheduled-tasks orders