1 回答

TA貢獻1829條經驗 獲得超7個贊
要從WC_Subscription對象獲取產品 ID,您需要使用以下方法循環遍歷訂單項(因為您可以有很多)get_items():
$order_items = $subscription->get_items();
// Loop through order items
foreach ( $order_items as $item_id => $item ) {
? ? // Get the WC_Product_Subscription Object
? ? $product = $item->get_product();
? ? // To get the subscription variable product ID and simple subscription? product ID
? ? $product_id = $item->get_product_id();
? ? // To get the variation subscription product ID
? ? $variation_id = $item->get_variation_id();
? ? // Or to get the simple subscription or the variation subscription product ID
? ? $_product_id = $product->get_id();
}
經過測試并有效。
- 1 回答
- 0 關注
- 139 瀏覽
添加回答
舉報