感谢您的回复,我确实看到了自动完成插件,但客户端要求这是手动方法。根据以下资源,我设法找出了一种适用于 Paypal 标准付款的方法:
http://codecharismic.com/run-your-own-damn-code-after-paypal-calls-woocommerce-back/
<?php
/**
* Auto Complete Woocommerce 'processing' orders
*/
add_action( 'valid-paypal-standard-ipn-request', 'handle_paypal_ipn_response', 50, 1 );
function handle_paypal_ipn_response( $formdata ) {
if ( !empty( $formdata['invoice'] ) && !empty( $formdata['custom'] ) ) {
if( $formdata['payment_status'] == 'Completed' ) {
// decode data
$order_data = json_decode($formdata['custom'], true);
// get order
$order_id = ($order_data) ? $order_data['order_id'] : '';
$order = new WC_Order( $order_id );
// got something to work with?
if ( $order ) {
if ($order->post->post_status == 'wc-processing'){
// Status success
WC_Gateway_Paypal::log( 'Changing order #' . $order->id . ' status from processing to completed');
$order->update_status( 'completed' );
} else {
// Status fail
WC_Gateway_Paypal::log( 'Status fail, order #' . $order->id . ' status is set to ' . $order->post->post_status . ', not processing');
}
} else {
// Order fail
WC_Gateway_Paypal::log( 'Fail, no order found');
}
} else {
// Payment fail
WC_Gateway_Paypal::log( 'Payment status fail, not completed');
}
}
}