Wordpress 切换订阅产品时更改订单状态
我正在使用WooCommerce和订阅。当客户在其订阅中切换项目时,他们将再次完成整个订单流程,订单状态设置为“正在处理/已完成”。我想将订单状态更改为Wordpress 切换订阅产品时更改订单状态,wordpress,woocommerce,hook-woocommerce,woocommerce-subscriptions,Wordpress,Woocommerce,Hook Woocommerce,Woocommerce Subscriptions,我正在使用WooCommerce和订阅。当客户在其订阅中切换项目时,他们将再次完成整个订单流程,订单状态设置为“正在处理/已完成”。我想将订单状态更改为切换订单。但我的问题是,我不知道我将使用什么数据来只针对交换订阅订单 add_action( 'woocommerce_thankyou', 'thankyou_change_order_status_to_switch' ); function thankyou_change_order_status_to_switch( $order_id
切换订单
。但我的问题是,我不知道我将使用什么数据来只针对交换订阅订单
add_action( 'woocommerce_thankyou', 'thankyou_change_order_status_to_switch' );
function thankyou_change_order_status_to_switch( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
if ( $order->has_status( 'processing' ) ) {
$order->update_status( 'switch-order' );
}
}
我设法解决了这个问题。这是代码
add_action( 'woocommerce_thankyou', 'thankyou_change_order_status_to_switch' );
function thankyou_change_order_status_to_switch( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
if( wcs_order_contains_subscription( $order, 'switch' ) && $order->has_status( 'processing' ) ){
$subscriptions = wcs_get_subscriptions_for_order( $order_id );
foreach( $subscriptions as $subscription_id => $subscription ){
$order->update_status( 'switch-order' );
}
}
}
我认为还不需要这一行代码
$subscriptions = wcs_get_subscriptions_for_order( $order_id );
foreach( $subscriptions as $subscription_id => $subscription ){}
我设法解决了这个问题。这是代码
add_action( 'woocommerce_thankyou', 'thankyou_change_order_status_to_switch' );
function thankyou_change_order_status_to_switch( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
if( wcs_order_contains_subscription( $order, 'switch' ) && $order->has_status( 'processing' ) ){
$subscriptions = wcs_get_subscriptions_for_order( $order_id );
foreach( $subscriptions as $subscription_id => $subscription ){
$order->update_status( 'switch-order' );
}
}
}
我认为还不需要这一行代码
$subscriptions = wcs_get_subscriptions_for_order( $order_id );
foreach( $subscriptions as $subscription_id => $subscription ){}