在用户未登录时,尝试为失败的订单(和暂停订阅)手动续订订阅时遇到问题。
当支付重试失败5次时,将保留旧订户。
他们可以收到续订链接,但需要先登录。
子续订链接:
{YOURSITE}.com/checkout/order-pay/{ORDER_ID}/?pay_for_order=true&key=wc_order\_{ORDER_KEY}&subscription_renewal=true
我试过了
Pay without need to login WooCommerce
回答代码来自@Stirling。
然而,代码似乎通过了登录要求,将正确的订单详细信息添加到购物车中。。。太棒了
但在处理订单时,订单不会链接到订阅。现有订阅没有续订,新订单是“孤立”订阅订单。
更新:上面的代码,在第一次加载时成功地将用户登录。如果你再次加载相同的续订链接,你会在结账时收到一条成功消息“完成结账以续订订阅”。如果处理完毕,重新订阅就会生效
就好像子代码首先要求用户在检查发生之前登录。。。这也与吴在这里操作的订阅代码一致
https://github.com/Automattic/woocommerce-subscriptions-core/blob/trunk/includes/class-wcs-cart-renewal.php
有人能帮忙吗?
从源代码来看可能
https://github.com/Automattic/woocommerce-subscriptions-core/blob/trunk/includes/class-wcs-cart-renewal.php
我也已经有了适用于初始订单阶段的代码,允许用户在不登录的情况下处理订单,适用于单个支付订单和订阅订单
此代码+Woo设置将
-
允许用户在不登录的情况下处理订单
-
如果用户没有帐户,请为其创建帐户
-
如果不存在,将创建一个帐户
-
即使用户未登录,也会将已付款订单添加到现有帐户。
add_filter( 'woocommerce_checkout_posted_data', 'filter_woocommerce_checkout_posted_data', 10, 1);
function filter_woocommerce_checkout_posted_data( $data) {
// Exit function if user is logged in to let checkout process as normal
if ( is_user_logged_in()) {
return $data;
}
/* If we have a user, we need to set the WP current user so that WooCommerce has a user and doesn't think it needs
to create another one for that user's email. If an existing user is not found, then create a new one. */
if ( !is_user_logged_in() && is_checkout()) {
// Make sure not logged in and are on checkout page.
$user = get_user_by('email', $data['billing_email']);
if ( !empty($user->ID) ) {
wp_set_current_user($user->ID);
$data['createaccount'] = 0; // Unset flag to create a new user.
}
else {
$data['createaccount'] = 1; // Set the flag to create a new user.
}
}
return $data;
}