更新:与WooCommerce版本3的兼容性
// => not a filter (an action hook)
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_paid_order', 10, 1 );
function custom_woocommerce_auto_complete_paid_order( $order_id ) {
if ( ! $order_id )
return;
$order = new WC_Order( $order_id );
// No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
if ( get_post_meta($order_id, '_payment_method', true) == 'bacs' || get_post_meta($order_id, '_payment_method', true) == 'cod' || get_post_meta($order_id, '_payment_method', true) == 'cheque' ) {
return;
}
// "completed" updated status for paid "processing" Orders (with all others payment methods)
elseif ( $order->has_status( 'processing' ) ) {
$order->update_status( 'completed' );
}
else {
return;
}
}