WordPress at Your Fingertips
function is not described

WC_Admin_Addons::map_product_card_data() public WC 1.0

Map data from different endpoints to a universal format

Search and featured products has a slightly different products' field names. Mapping converts different data structures into a universal one for further processing.

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

No Hooks.

Return

Object. Converted data.

Usage

$result = WC_Admin_Addons::map_product_card_data( $data );
$data(mixed) (required)
Product Card Data.

Code of WC_Admin_Addons::map_product_card_data() WC 5.9.0

public static function map_product_card_data( $data ) {
	$mapped = (object) null;

	$type = $data->type ?? null;

	// Icon.
	$mapped->icon = $data->icon ?? null;
	if ( null === $mapped->icon && 'banner' === $type ) {
		// For product-related banners icon is a product's image.
		$mapped->icon = $data->image ?? null;
	}
	// URL.
	$mapped->url = $data->link ?? null;
	if ( empty( $mapped->url ) ) {
		$mapped->url = $data->url ?? null;
	}
	// Title.
	$mapped->title = $data->title ?? null;
	// Vendor Name.
	$mapped->vendor_name = $data->vendor_name ?? null;
	if ( empty( $mapped->vendor_name ) ) {
		$mapped->vendor_name = $data->vendorName ?? null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
	}
	// Vendor URL.
	$mapped->vendor_url = $data->vendor_url ?? null;
	if ( empty( $mapped->vendor_url ) ) {
		$mapped->vendor_url = $data->vendorUrl ?? null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
	}
	// Description.
	$mapped->description = $data->excerpt ?? null;
	if ( empty( $mapped->description ) ) {
		$mapped->description = $data->description ?? null;
	}
	$has_currency = ! empty( $data->currency ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

	// Is Free.
	if ( $has_currency ) {
		$mapped->is_free = 0 === (int) $data->price;
	} else {
		$mapped->is_free = '$0.00' === $data->price;
	}
	// Price.
	if ( $has_currency ) {
		$mapped->price = wc_price( $data->price, array( 'currency' => $data->currency ) );
	} else {
		$mapped->price = $data->price;
	}
	// Rating.
	$mapped->rating = $data->rating ?? null;
	if ( null === $mapped->rating ) {
		$mapped->rating = $data->averageRating ?? null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
	}
	// Reviews Count.
	$mapped->reviews_count = $data->reviews_count ?? null;
	if ( null === $mapped->reviews_count ) {
		$mapped->reviews_count = $data->reviewsCount ?? null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
	}
	// Featured & Promoted product card.
	// Label.
	$mapped->label = $data->label ?? null;
	// Primary color.
	$mapped->primary_color = $data->primary_color ?? null;
	// Text color.
	$mapped->text_color = $data->text_color ?? null;
	// Button text.
	$mapped->button = $data->button ?? null;

	return $mapped;
}