WC_Admin_Marketplace_Promotions::fetch_marketplace_promotions()private staticWC 1.0

Get promotions to show in the Woo in-app marketplace and load them into a transient with a 12-hour life. Run as a recurring scheduled action.

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

Возвращает

Массив.

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

$result = WC_Admin_Marketplace_Promotions::fetch_marketplace_promotions();

Код WC_Admin_Marketplace_Promotions::fetch_marketplace_promotions() WC 9.4.2

private static function fetch_marketplace_promotions() {
	/**
	 * Filter to suppress the requests for and showing of marketplace promotions.
	 *
	 * @since 8.8
	 */
	if ( apply_filters( 'woocommerce_marketplace_suppress_promotions', false ) ) {
		return array();
	}

	// Fetch promotions from the API.
	$fetch_options  = array(
		'auth'    => true,
		'country' => true,
	);
	$raw_promotions = WC_Admin_Addons::fetch( self::PROMOTIONS_API_URL, $fetch_options );

	// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
	if ( is_wp_error( $raw_promotions ) ) {
		/**
		 * Allows connection error to be handled.
		 *
		 * @since 8.7
		 */
		do_action( 'woocommerce_page_wc-addons_connection_error', $raw_promotions->get_error_message() );
	}

	$response_code = (int) wp_remote_retrieve_response_code( $raw_promotions );
	if ( 200 !== $response_code ) {
		/**
		 * Allows connection error to be handled.
		 *
		 * @since 8.7
		 */
		do_action( 'woocommerce_page_wc-addons_connection_error', $response_code );
	}

	$promotions = json_decode( wp_remote_retrieve_body( $raw_promotions ), true );

	if ( ! is_array( $promotions ) ) {
		$promotions = array();

		/**
		 * Allows connection error to be handled.
		 *
		 * @since 8.7
		 */
		do_action( 'woocommerce_page_wc-addons_connection_error', 'Malformed response' );
	}
	// phpcs:enable WordPress.NamingConventions.ValidHookName.UseUnderscores

	return $promotions;
}