WordPress at Your Fingertips
function is not described

WC_Admin_Addons::render_featured() public WC 1.0

Render featured products and banners using WCCOM's the Featured 2.0 Endpoint

{} It's a method of the class: WC_Admin_Addons{}

No Hooks.

Return

null. Nothing.

Usage

$result = WC_Admin_Addons::render_featured();

Code of WC_Admin_Addons::render_featured() WC 5.9.0

public static function render_featured() {
	$featured = get_transient( 'wc_addons_featured_2' );
	if ( false === $featured ) {
		$headers = array();
		$auth    = WC_Helper_Options::get( 'auth' );

		if ( ! empty( $auth['access_token'] ) ) {
			$headers['Authorization'] = 'Bearer ' . $auth['access_token'];
		}

		$parameter_string = '';
		$country          = WC()->countries->get_base_country();
		if ( ! empty( $country ) ) {
			$parameter_string = '?' . http_build_query( array( 'country' => $country ) );
		}

		// Important: WCCOM Extensions API v2.0 is used.
		$raw_featured = wp_safe_remote_get(
			'https://woocommerce.com/wp-json/wccom-extensions/2.0/featured' . $parameter_string,
			array(
				'headers'    => $headers,
				'user-agent' => 'WooCommerce Addons Page',
			)
		);

		if ( ! is_wp_error( $raw_featured ) ) {
			$featured = json_decode( wp_remote_retrieve_body( $raw_featured ) );
			if ( $featured ) {
				set_transient( 'wc_addons_featured_2', $featured, DAY_IN_SECONDS );
			}
		}
	}

	if ( ! empty( $featured ) ) {
		self::output_featured( $featured );
	}
}