Ensure that all Manual Renewal orders with WooCommerce Subscriptions & WooCommerce Payments are automatically 'Completed'

huangapple go评论169阅读模式
英文:

Ensure that all Manual Renewal orders with WooCommerce Subscriptions & WooCommerce Payments are automatically 'Completed'

问题

抱歉,我无法为您提供代码翻译,但我可以提供关于您的代码和问题的建议。如果您需要帮助,请告诉我您的问题的具体内容,我将尽力提供解决方案。

英文:

I've built a website using WooCommerce Subscriptions, which uses WooCommerce Payments as the payment gateway. Users have the options to subscribe on either a monthly or an annual basis. All subscriptions come with a free month's trial.

Currently, subscribers are only able to pay using a credit/debit card. For these users, their subscription is temporarily 'on-hold' until the order completes and when the order completes, the subscription returns to the 'active' status.

However, a select few subscribers have been given a 100% discount voucher. For these, they are marked as 'Via Manual Renewal'. When either parent or renewal orders are created, tthey fail to be marked as 'completed'. They are always left as 'pending'. I'm guessing this has something to do with the fact that these are 'Manual Renewal' orders.

I've tried to create some PHP code to add in as a snippet, to catch when these users have orders created, so that they can automatically be marked as 'completed'. This is what I have put together so far.

add_action( 'woocommerce_thankyou', 'sd_woocommerce_auto_complete_order' );
function sd_woocommerce_auto_complete_order( $order_id ) { 
    if ( ! $order_id ) {
        return;
    }
    $order = wc_get_order( $order_id );
    $order->update_status( 'completed' );
}

add_action('woocommerce_subscription_payment_complete', 'subscription_payment_complete_hook_callback', 10, 1);
function subscription_payment_complete_hook_callback( $subscription ) {
    // Get the current order
    $current_order = $subscription->get_last_order( 'all', 'any' );

    // For Paypal recurring orders
    if( $current_order->get_payment_method() === 'woocommerce_payments' ) {

        // Update status to completed
        $current_order->update_status('completed');
    }
}

Unfortunately, this doesn't seem to have an effect, in that I still have to manually mark these users' orders as 'complete'.

Can someone please help me identify the issue with the code I've created, and how I might be able to update it, so that I can ensure all manual renewal orders are marked as 'completed' automatically? Or alternatively, is there a way to change Manual Renewal orders, so that they don't need to constantly generate orders?

Thank you!

答案1

得分: 0

所以事实证明,它比我想象的要简单得多。

基本上,对于WooCommerce来说,订单是否通过“手动续订”无关紧要,不会自动标记为“已完成”。

实际上,要使订单自动标记为“已完成”,WooCommerce需要知道站点所有者/管理员无需采取任何行动,一旦成功收到付款。

因此,任何创建的产品都必须标记为“虚拟”和“可下载”。我的产品只标记为“虚拟”,这就是发生这种情况的原因。现在它们都标记为两者,所有我的订单似乎都已自动标记为“已完成”了。 Ensure that all Manual Renewal orders with WooCommerce Subscriptions & WooCommerce Payments are automatically 'Completed'

英文:

So as it turns out, it was a lot simpler than I thought.

Basically, with WooCommerce, the fact that an order was 'via Manual Renewal' was irrelevant to orders not automatically being marked as 'Completed'.

Essentially, for an order to be marked as 'Completed' automatically, WooCommerce needs to know that no action needs to be taken on behalf of the site owner/admin, once a payment has been received successfully.

Therefore, any product created must be marked as both 'Virtual' and 'Downloadable'. My products were marked as 'Virtual' only, which was why it was happening. Now that they're marked as both, all my orders seem to have been marked as 'Completed' automatically now. Ensure that all Manual Renewal orders with WooCommerce Subscriptions & WooCommerce Payments are automatically 'Completed'

huangapple
  • 本文由 发表于 2023年6月6日 04:06:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定