WC_Plugin_Api_Updater::override_products_api_response()public staticWC 1.0

Override the products API to fetch data from the Helper API if it's a Woo product.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$result = WC_Plugin_Api_Updater::override_products_api_response( $response, $action, $args );
$response(объект) (обязательный)
The response core needs to display the modal.
$action(строка) (обязательный)
The requested action.
$args(объект) (обязательный)
Arguments passed to the API.

Код WC_Plugin_Api_Updater::override_products_api_response() WC 9.4.2

public static function override_products_api_response( $response, $action, $args ) {
	if ( empty( $args->slug ) ) {
		return $response;
	}

	// Only for slugs that start with woocommerce-com-.
	if ( 0 !== strpos( $args->slug, 'woocommerce-com-' ) ) {
		return $response;
	}

	$clean_slug = str_replace( 'woocommerce-com-', '', $args->slug );

	// Look through update data by slug.
	$update_data = WC_Helper_Updater::get_update_data();
	$products    = wp_list_filter( $update_data, array( 'slug' => $clean_slug ) );

	if ( empty( $products ) ) {
		return $response;
	}

	$product_id = array_keys( $products );
	$product_id = array_shift( $product_id );

	// Fetch the product information from the Helper API.
	$request = WC_Helper_API::get(
		add_query_arg(
			array(
				'product_id' => absint( $product_id ),
			),
			'info'
		),
		array( 'authenticated' => true )
	);

	$results = json_decode( wp_remote_retrieve_body( $request ), true );
	if ( ! empty( $results ) ) {
		$response = (object) $results;
	}

	return $response;
}