WooCommerce Subscriptions - Get product of a specific subscription

前端 未结 3 1651
南笙
南笙 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:43

    Get product from woocommerce subscription full code with examples of use:

    if ( sizeof( $subscription_items = $subscription->get_items() ) > 0 ) {
        foreach ( $subscription_items as $item_id => $item ) {
            $product = $item->get_product();
    
            //Examples of use
            $product->get_id();
            $product->get_sku();
            $product->get_image('post-thumbnail', ['class' => 'alignleft'], false); // main image
    
            $product_id = wcs_get_canonical_product_id( $item ); // get product id directly from item
        }
    }
    

提交回复
热议问题