WooCommerce Subscriptions - Get product of a specific subscription

前端 未结 3 1654
南笙
南笙 2021-01-19 19:02

Is there a way to get from $product from $subscription?

Thanks to this post, I know that from $subscription I can get $o

3条回答
  •  终归单人心
    2021-01-19 19:44

    It is possible to get the products from either the Subscription or the matching order, as a subscription object is an extension of the WC_Order class.

    $subscription_products = $subscription->get_items();
    $order_products = $subscription->order->get_items();
    

    In most situations where you provide subscription services, both of these will be equivalent or $order_products should at least contain all products found within $subscription_products.

    A notable exception is when you create a subscription manually; no order will be attached to the subscription, so $subscription->order may not be a valid WC_Order object.

提交回复
热议问题