WC_WCCOM_Site_Installation_Step_Get_Product_Info::run()publicWC 1.0

Run the step installation process.

Метод класса: WC_WCCOM_Site_Installation_Step_Get_Product_Info{}

Хуков нет.

Возвращает

Массив.

Использование

$WC_WCCOM_Site_Installation_Step_Get_Product_Info = new WC_WCCOM_Site_Installation_Step_Get_Product_Info();
$WC_WCCOM_Site_Installation_Step_Get_Product_Info->run();

Код WC_WCCOM_Site_Installation_Step_Get_Product_Info::run() WC 9.8.2

public function run() {
	$product_id = $this->state->get_product_id();

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

	if ( 200 !== wp_remote_retrieve_response_code( $request ) ) {
		throw new Installer_Error( Installer_Error_Codes::FAILED_GETTING_PRODUCT_INFO );
	}

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

	if ( ! isset( $result['_product_type'], $result['name'] ) ) {
		throw new Installer_Error( Installer_Error_Codes::INVALID_PRODUCT_INFO_RESPONSE );
	}

	if ( ! empty( $result['_wporg_product'] ) ) {
		$download_url = $this->get_wporg_download_url( $result );
	} else {
		$download_url = $this->get_wccom_download_url( $product_id );
	}

	$this->state->set_product_type( $result['_product_type'] );
	$this->state->set_product_name( $result['name'] );
	$this->state->set_download_url( $download_url );

	return $this->state;
}