1
我想請教如何使用過濾器/行動 插件文件位置,以覆蓋該woocommerce功能(wp_schedule_single_event和post_status):/woocommerce/includes/wc-order-functions.php過濾woocommerce取消未支付的訂單
原始文件:
/**
* Cancel all unpaid orders after held duration to prevent stock lock for those products.
*
* @access public
*/
function wc_cancel_unpaid_orders() {
global $wpdb;
$held_duration = get_option('woocommerce_hold_stock_minutes');
if ($held_duration < 1 || get_option('woocommerce_manage_stock') != 'yes')
return;
$date = date("Y-m-d H:i:s", strtotime('-' . absint($held_duration) . ' MINUTES', current_time('timestamp')));
$unpaid_orders = $wpdb->get_col($wpdb->prepare("
SELECT posts.ID
FROM {$wpdb->posts} AS posts
WHERE posts.post_type IN ('" . implode("','", wc_get_order_types()) . "')
AND posts.post_status = 'wc-pending'
AND posts.post_modified < %s
", $date));
if ($unpaid_orders) {
foreach ($unpaid_orders as $unpaid_order) {
$order = wc_get_order($unpaid_order);
if (apply_filters('woocommerce_cancel_unpaid_order', 'checkout' === get_post_meta($unpaid_order, '_created_via', true), $order)) {
$order->update_status('cancelled', __('Unpaid order cancelled - time limit reached.', 'woocommerce'));
}
}
}
wp_clear_scheduled_hook('woocommerce_cancel_unpaid_orders');
wp_schedule_single_event(time() + (absint($held_duration) * 60), 'woocommerce_cancel_unpaid_orders');
}
add_action('woocommerce_cancel_unpaid_orders', 'wc_cancel_unpaid_orders');
我想改變這個變量:
$unpaid_orders = $wpdb->get_col($wpdb->prepare("
SELECT posts.ID
FROM {$wpdb->posts} AS posts
WHERE posts.post_type IN ('" . implode("','", wc_get_order_types()) . "')
AND posts.post_status = '**wc-on-hold**'
AND posts.post_modified < %s
", $date));
這
**wp_schedule_single_event(time() + 3600),** 'woocommerce_cancel_unpaid_orders');
請幫助..
感謝 Azreal
謝謝,現在工作:) – Azreal