本文介绍了WooCommerce订阅-获取特定订阅的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法从$subscription中获取$product?

感谢此帖子,我知道从$subscription可以得到$order:

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

$order = $subscription->order;

这也是可能的吗?

$product = $subscription->product;

或者:

$product = $order->product;

推荐答案

由于订阅对象是WC_Order类的扩展,因此可以从订阅"或匹配的订单中获取产品.

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();

在大多数情况下,如果您提供订阅服务,则这两者将是等效的,或者$order_products应该至少包含在$subscription_products中找到的所有产品.

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.

一个明显的例外是您手动创建订阅时;没有订单将附加到订阅,因此$subscription->order可能不是有效的WC_Order对象.

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.

这篇关于WooCommerce订阅-获取特定订阅的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 17:38