• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WC_WCCOM_Site_Installer::get_product_info() – Get product info from its ID.

You appear to be a bot. Output may be restricted

Description

Get product info from its ID.

Usage

$array|\WP_Error = WC_WCCOM_Site_Installer::get_product_info( $product_id );

Parameters

$product_id
( int ) required – Product ID.

Returns

array|\WP_Error

Source

File name: woocommerce/includes/wccom-site/class-wc-wccom-site-installer.php
Lines:

1 to 45 of 45
  private static function get_product_info( $product_id ) {
    $product_info = array(
      'download_url' => '',
      'product_type' => '',
    );

    // Get product info from woocommerce.com.
    $request = WC_Helper_API::get(
      add_query_arg(
        array( 'product_id' => absint( $product_id ) ),
        'info'
      ),
      array(
        'authenticated' => true,
      )
    );

    if ( 200 !== wp_remote_retrieve_response_code( $request ) ) {
      return new WP_Error( 'product_info_failed', __( 'Failed to retrieve product info from woocommerce.com', 'woocommerce' ) );
    }

    $result = json_decode( wp_remote_retrieve_body( $request ), true );

    $product_info['product_type'] = $result['_product_type'];
    $product_info['product_name'] = $result['name'];

    if ( ! empty( $result['_wporg_product'] ) && ! empty( $result['download_link'] ) ) {
      // For wporg product, download is set already from info response.
      $product_info['download_url'] = $result['download_link'];
    } elseif ( ! WC_Helper::has_product_subscription( $product_id ) ) {
      // Non-wporg product needs subscription.
      return new WP_Error( 'missing_subscription', __( 'Missing product subscription', 'woocommerce' ) );
    } else {
      // Retrieve download URL for non-wporg product.
      WC_Helper_Updater::flush_updates_cache();
      $updates = WC_Helper_Updater::get_update_data();
      if ( empty( $updates[ $product_id ]['package'] ) ) {
        return new WP_Error( 'missing_product_package', __( 'Could not find product package.', 'woocommerce' ) );
      }

      $product_info['download_url'] = $updates[ $product_id ]['package'];
    }

    return $product_info;
  }
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 8th February 2020

Primary Sidebar

Information

Function name: WC_WCCOM_Site_Installer::get_product_info
Class ref: WC_WCCOM_Site_Installer
Plugin ref: WooCommerce
Version: 4.8.0
Sourcefile: includes/wccom-site/class-wc-wccom-site-installer.php
File ref: includes/wccom-site/class-wc-wccom-site-installer.php
Deprecated?: No
API Letters: G,I,S,W

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites