付款过程完成后更新woocommerce订单状态并重定向到商店 [英] update woocommerce order status after payment process complete and redirect to store
问题描述
我正在将woo-commerce用于我的购物网站.我想在完成付款后将订单状态更新为完成,然后返回成功页面.
I am using woo-commerce for my shopping site. I want to update the order status to complete after payment was made and then return to a success page.
我使用了以下代码:
add_filter( 'woocommerce_payment_complete_order_status', 'my_change_status_function', 10, 2 );
function my_change_status_function ($order_status, $order_id) {
$order = new WC_Order($order_id);
return 'completed';
}
但是此功能在付款之前被调用并重定向到付款页面.
But this function is called before the payment was made and redirects to the payment page.
我想在付款完成后更改状态,然后返回到redirect
URL.
I want to change the status after the payment was completed and then return to redirect
URL.
这是我的重定向链接:
http://example.com/checkout/order-received/82/?key=wc_order_5614e28c9d183&state=return
但是当我使用woocommerce_payment_complete_order_status
挂钩时,状态没有改变.
付款完成后应调用该挂钩.
But the status is not changing when I use the woocommerce_payment_complete_order_status
hook.
The hook should be called after the payment is completed.
推荐答案
尝试在插件中使用以下代码
Try using the following code in your plugin
add_action( 'woocommerce_payment_complete', 'my_change_status_function' );
function my_change_status_function( $order_id ) {
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
}
这篇关于付款过程完成后更新woocommerce订单状态并重定向到商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!