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; }