حذف پرداخت های تکمیل نشده

Mesmaili

کاربر عضو
سلام دوستان.

میخوایم پرداخت هایی که کامل نمیشن، از حساب کاربری مشتری کلا حذف شه

یعنی توی سبد و... نمونه که دوباره لاگین کرد داشته باشه اونو

راهی هست؟

 

Mohammad

مدیر انجمن
پرسنل مدیریت
لطفا ابتدا در لوکال ازمایش کن کد زیر رو. مطمئن نیستم

کد:
add_action( 'woocommerce_order_status_failed', 'the_dramatist_woocommerce_auto_delete_order' );
add_action( 'woocommerce_order_status_pending', 'the_dramatist_woocommerce_auto_delete_order' );
add_action( 'woocommerce_order_status_cancelled', 'the_dramatist_woocommerce_auto_delete_order' );

function the_dramatist_woocommerce_auto_delete_order( $order_id ) {
    // 5*60 = 300 seconds. Here 1minute = 60 seconds.
    wp_schedule_single_event(tim() + 300, 'the_dramatist_main_delete_event', $order_id);
}

function the_dramatist_main_delete_event( $order_id ) {
    global $woocommerce;
    $order = new WC_Order( $order_id );
    $order_status = $order->get_status();
    if ( !$order_id )
        return false;
    if ('cancelled' == $order_status || 'failed' == $order_status ||   'pending' == $order_status ) {
        wp_delete_post($order_id,true);
        return true;
    }
    return false;
}
 
بالا