在WooCommerce中更新订单状态更改的付款日期

时间:2020-10-20 08:55:12

标签: woocommerce

我对旧的未付款订单有问题,最终会得到付款-付款日期仍将设置为失败日期,但我需要将此设置为实际付款日期。

付款后,订单将进入处理过程,因此可用于更改日期。希望在从待处理的付款手动更改为处理状态时,也可以使用此功能。

在下面尝试过但不起作用-这样做的最佳方法是什么?

add_action( 'woocommerce_loaded', 'wc_custom_loaded' );

function wc_custom_loaded() {
    $old_statuses = array(
        'failed',
        'pending',
        'processing',
        'on-hold',
        'cancelled',
        'refunded'
    );
    foreach ( $old_statuses as $old_status ) {
        add_action( 'woocommerce_order_status_' . $old_status . '_to_completed', 'wc_custom_change_posted_date', 99, 1 );
    }
}

function wc_custom_change_posted_date( $order_id ) {
    $order = wc_get_order( $order_id );
    $args = array(
        'post_id' => $order_id,
        'post_date' => '',
        'post_date_gmt' => '',
    );
    wp_update_post( $args );
}

0 个答案:

没有答案