admin管理员组文章数量:1287535
I am trying to find a solution for redirecting existing customers to a specific url after checkout. I'm not sure if the Thank you page redirect is sufficient for the process. can you assist?
I am trying to find a solution for redirecting existing customers to a specific url after checkout. I'm not sure if the Thank you page redirect is sufficient for the process. can you assist?
Share Improve this question asked Jul 28, 2021 at 12:05 SheldonSheldon 31 bronze badge 1- What have you tried so far? – Tony Djukic Commented Aug 5, 2021 at 22:27
1 Answer
Reset to default 0The following should suffice. It will redirect to your custom URL only if the order has not failed.
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';
// double check this order has gone through okay and then redirect them
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
}
}
function woocommerce_redirect_after_checkout(){ global $wp; if (is_checkout()&&!empty($wp->query_vars['order-completed'])){ $redirect_url='https://example'; wp_redirect($rediect_url); exit; } }
本文标签: pluginsHow would I Redirect an existing WooCommerce customer to a specific url after Checkout
版权声明:本文标题:plugins - How would I Redirect an existing WooCommerce customer to a specific url after Checkout 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741263603a2368055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论