WordPress at Your Fingertips
function is not described

WC_Admin_Addons::format_promotions() public WC 1.0

Format the promotion data ready for display, ie fetch locales and actions.

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

No Hooks.

Return

Array. Array of formatted promotions ready for output.

Usage

$result = WC_Admin_Addons::format_promotions( $promotions ): array;
$promotions(array) (required)
Array of promotoin objects.

Code of WC_Admin_Addons::format_promotions() WC 5.9.0

public static function format_promotions( array $promotions ): array {
	$formatted_promotions = array();
	foreach ( $promotions as $promotion ) {
		// Get the matching locale or fall back to en-US.
		$locale = PromotionRuleEngine\SpecRunner::get_locale( $promotion->locales );
		if ( null === $locale ) {
			continue;
		}

		$promotion_actions = array();
		if ( ! empty( $promotion->actions ) ) {
			foreach ( $promotion->actions as $action ) {
				$action_locale = PromotionRuleEngine\SpecRunner::get_action_locale( $action->locales );
				$url           = self::get_action_url( $action );

				$promotion_actions[] = array(
					'name'    => $action->name,
					'label'   => $action_locale->label,
					'url'     => $url,
					'primary' => isset( $action->is_primary ) ? $action->is_primary : false,
				);
			}
		}

		$formatted_promotions[] = array(
			'title'       => $locale->title,
			'description' => $locale->description,
			'image'       => ( 'http' === substr( $locale->image, 0, 4 ) ) ? $locale->image : WC()->plugin_url() . $locale->image,
			'image_alt'   => $locale->image_alt,
			'actions'     => $promotion_actions,
		);
	}
	return $formatted_promotions;
}