programing

WooCommerce - 주문 ID에서 구독 ID 가져오기

muds 2023. 11. 2. 22:10
반응형

WooCommerce - 주문 ID에서 구독 ID 가져오기

나는 액션 훅에서 그것을 얻으려 하고 있습니다.

그것은 고객이 전환할 때마다 변경되는 것을 나에게 줍니다.

예를 들어,가 인 경우 원본은 입니다.

이제 고객이 만든 모든 스위치는 새로운 주문 ID를 생성하며, 위의 작업을 통해 이 ID를 제공합니다.이 시점에서 나는 , , , 그리고 원본을 가지고 있습니다 ,

어떻게 하면 현재 주문한 것을 받을 수 있습니까?

$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, array( 'order_type' => 'any' ) );
    // We get all related subscriptions 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 
    // ...
}

언급URL : https://stackoverflow.com/questions/43150761/woocommerce-get-the-subscription-id-from-the-order-id

반응형