我正在尝试从操作挂钩woocommerce_order_status_changed中获取订阅ID.
它给我订单ID,客户每次切换都会更改该ID.
例如:如果订阅ID为10,则原始订单ID为9.
现在,客户进行的每个开关都会生成一个新的订单ID,上面的操作会为您提供该ID.此时,我有$customer_id,$order_id和原始帖子ID,即9,
如何获取当前订单的订阅ID?
谢谢
解决方法:
您可以使用专用功能wcs_get_subscriptions_for_order()
来检索$subscription ID.
因此,这可能是您的代码:
add_action('woocommerce_order_status_changed', 'action_order_status_changed');
function action_order_status_changed( $order_id ){
$subscriptions_ids = wcs_get_subscriptions_for_order( $order_id );
// We get the related subscription for this order
foreach( $subscriptions_ids as $subscription_id => $subscription_obj )
if($subscription_obj->order->id == $order_id) break; // Stop the loop
// The subscription ID: $subscription_id
// The An instance of the Subscription object: $subscription_obj
// ...
}