WC_WCCOM_Site_Installer::get_product_info()
Get product info from its ID.
Метод класса: WC_WCCOM_Site_Installer{}
Хуков нет.
Возвращает
Массив|\WP_Error
.
Использование
$result = WC_WCCOM_Site_Installer::get_product_info( $product_id );
- $product_id(int) (обязательный)
- Product ID.
Список изменений
С версии 3.7.0 | Введена. |
Код WC_WCCOM_Site_Installer::get_product_info() WC WCCOM Site Installer::get product info WC 7.3.0
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; }