I
I
Igor2020-11-07 11:33:09
WooCommerce
Igor, 2020-11-07 11:33:09

Perform action on auto-cancel WoocCommerce order?

Good afternoon

Woocommerce automatically cancels orders from statuses pending payment to canceled after a specified period of time

Tell me how to subscribe to this event to perform its functionality.

I'm trying like this, If I manually change the status then it works, but with auto-cancel it doesn't work. In functions.php

add_action( 'woocommerce_order_edit_status', 'switips_update_order', 10, 1 );
add_action( 'woocommerce_order_status_changed', 'switips_update_order', 10, 1 );
add_action( 'woocommerce_order_status_cancelled', 'switips_update_order', 10, 1 );
function switips_update_order( $order_id )
{
    $order = new WC_Order($order_id);
    #Для проверки работоспособности
    setcookie( 'order', (string)$order->get_status(), time() + 3600 * 24 * 30, "/");
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-11-07
@peretc001

I found that a cron job is created to cancel an order

function wc_cancel_unpaid_orders() {
  ...

  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' );

I'm trying to subscribe to it, it doesn't work either.
add_action( 'wc_cancel_unpaid_orders', 'switips_update_order_test', 10, 1 );
function switips_update_order_test( $order_id )
{
    setcookie('order', 'cancelled', time() + 3600 * 24 * 30, "/");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question