WC_Admin_Addons::format_promotions()public staticWC 1.0

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

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

Хуков нет.

Возвращает

Массив. Array of formatted promotions ready for output.

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

$result = WC_Admin_Addons::format_promotions( $promotions ): array;
$promotions(массив) (обязательный)
Array of promotoin objects.

Код WC_Admin_Addons::format_promotions() WC 8.7.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;
}