Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
WC_WCCOM_Site_Installer::get_product_info( int $product_id )
Get product info from its ID.
Description Description
Parameters Parameters
- $product_id
-
(Required) Product ID.
Return Return
(array|WP_Error)
Source Source
File: includes/wccom-site/class-wc-wccom-site-installer.php
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; }
Changelog Changelog
Version | Description |
---|---|
3.7.0 | Introduced. |