以下内容就足够了。只有在订单没有失败的情况下,它才会重定向到您的自定义URL。
add_action( \'woocommerce_thankyou\', \'ii_redirect_thankyou\');
function ii_redirect_thankyou( $order_id ){
$customer_orders = get_posts( array(
\'numberposts\' => 2, // getting 2 as by the time this purchase has happened the count will be 1.
\'meta_key\' => \'_customer_user\',
\'meta_value\' => get_current_user_id(),
\'post_type\' => \'shop_order\', // WC orders post type
\'post_status\' => \'wc-completed\', // Only orders with "completed" status
\'fields\' => \'ids\', // Return Ids "completed"
) );
if ( count($customer_orders) > 1 ) {
$order = wc_get_order( $order_id );
$url = \'http://example.com\';
// double check this order has gone through okay and then redirect them
if ( ! $order->has_status( \'failed\' ) ) {
wp_safe_redirect( $url );
exit;
}
}
}
函数woocommerce\\u redirect\\u after\\u checkout(){global$wp;if(is\\u checkout()&;!empty($wp->;query\\u vars[\'order-completed\'){$redirect\\u url=\'https://example.com\';wp\\u重定向($redect\\u url);退出;}}