woocommerce_cancel_unpaid_order filter-hookWC 2.0.3

Filters whether an unpaid order should be automatically cancelled.

By default, only orders created via customer-facing checkout (classic checkout or checkout block) are automatically cancelled. Orders created through other means (admin, REST API, plugins) are not cancelled.

Usage

add_filter( 'woocommerce_cancel_unpaid_order', 'wp_kama_woocommerce_cancel_unpaid_order_filter', 10, 2 );

/**
 * Function for `woocommerce_cancel_unpaid_order` filter-hook.
 * 
 * @param bool     $should_cancel Whether the unpaid order should be cancelled.
 * @param WC_Order $order         The unpaid order object.
 *
 * @return bool
 */
function wp_kama_woocommerce_cancel_unpaid_order_filter( $should_cancel, $order ){

	// filter...
	return $should_cancel;
}
$should_cancel(true|false)
Whether the unpaid order should be cancelled.
Default: true for orders created via 'checkout' or 'store-api', false otherwise
$order(WC_Order)
The unpaid order object.

Changelog

Since 2.0.3 Introduced.
Since 10.6.0 Added 'store-api' to the list of order sources that are automatically cancelled.

Where the hook is called

wc_cancel_unpaid_orders()
woocommerce_cancel_unpaid_order
woocommerce/includes/wc-order-functions.php 1141
if ( apply_filters( 'woocommerce_cancel_unpaid_order', in_array( $order->get_created_via(), array( 'checkout', 'store-api' ), true ), $order ) ) {

Where the hook is used in WooCommerce

Usage not found.