WordPress at Your Fingertips
function is not described

WC_Admin_Addons::render_product_card() public WC 1.0

Render a product card

There's difference in data structure (e.g. field names) between endpoints such as search and featured. Inner mapping helps to use universal field names for further work.

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

No Hooks.

Return

null. Nothing.

Usage

$result = WC_Admin_Addons::render_product_card( $data, $block_type );
$data(mixed) (required)
Product data.
$block_type(string)
Block type that's different from the default product card, e.g. a banner.
Default: null

Code of WC_Admin_Addons::render_product_card() WC 5.9.0

<?php
public static function render_product_card( $data, $block_type = null ) {
	$mapped      = self::map_product_card_data( $data );
	$product_url = self::add_in_app_purchase_url_params( $mapped->url );
	$class_names = array( 'product' );
	// Specify a class name according to $block_type (if it's specified).
	if ( null !== $block_type ) {
		$class_names[] = 'addons-product-' . $block_type;
	}

	$product_details_classes = 'product-details';
	if ( 'banner' === $block_type ) {
		$product_details_classes .= ' addon-product-banner-details';
	}

	if ( isset( $mapped->label ) && 'promoted' === $mapped->label ) {
		$product_details_classes .= ' promoted';
	} elseif ( isset( $mapped->label ) && 'featured' === $mapped->label ) {
		$product_details_classes .= ' featured';
	}

	if ( 'promoted' === $mapped->label
		 && ! empty( $mapped->primary_color )
		 && ! empty( $mapped->text_color )
		 && ! empty( $mapped->button ) ) {
		// Promoted product card.
		?>
		<li class="product">
			<div class="<?php echo esc_attr( $product_details_classes ); ?>" style="border-top: 5px  solid <?php echo esc_html( $mapped->primary_color ); ?>;">
				<span class="label promoted"><?php esc_attr_e( 'Promoted', 'woocommerce' ); ?></span>
				<a href="<?php echo esc_url( $product_url ); ?>">
					<h2><?php echo esc_html( $mapped->title ); ?></h2>
				</a>
				<p><?php echo wp_kses_post( $mapped->description ); ?></p>
			</div>
			<div class="product-footer-promoted">
				<span class="icon"><img src="<?php echo esc_url( $mapped->icon ); ?>" /></span>
				<a class="addons-button addons-button-promoted" style="background: <?php echo esc_html( $mapped->primary_color ); ?>; color: <?php echo esc_html( $mapped->text_color ); ?>;" href="<?php echo esc_url( $product_url ); ?>">
					<?php echo esc_html( $mapped->button ); ?>
				</a>
			</div>
		</li>
		<?php
	} else {
		// Normal or "featured" product card.
		?>
		<li class="<?php echo esc_attr( implode( ' ', $class_names ) ); ?>">
			<div class="<?php echo esc_attr( $product_details_classes ); ?>">
				<div class="product-text-container">
					<?php if ( isset( $mapped->label ) && 'featured' === $mapped->label ) { ?>
						<span class="label featured"><?php esc_attr_e( 'Featured', 'woocommerce' ); ?></span>
					<?php } ?>
					<a href="<?php echo esc_url( $product_url ); ?>">
						<h2><?php echo esc_html( $mapped->title ); ?></h2>
					</a>
					<?php if ( ! empty( $mapped->vendor_name ) && ! empty( $mapped->vendor_url ) ) : ?>
						<div class="product-developed-by">
							<?php
							$vendor_url = add_query_arg(
								array(
									'utm_source'   => 'extensionsscreen',
									'utm_medium'   => 'product',
									'utm_campaign' => 'wcaddons',
									'utm_content'  => 'devpartner',
								),
								$mapped->vendor_url
							);

							printf(
							/* translators: %s vendor link */
								esc_html__( 'Developed by %s', 'woocommerce' ),
								sprintf(
									'<a class="product-vendor-link" href="%1$s" target="_blank">%2$s</a>',
									esc_url_raw( $vendor_url ),
									esc_html( $mapped->vendor_name )
								)
							);
							?>
						</div>
					<?php endif; ?>
					<p><?php echo wp_kses_post( $mapped->description ); ?></p>
				</div>
				<?php if ( ! empty( $mapped->icon ) ) : ?>
					<span class="product-img-wrap">
						<?php /* Show an icon if it exists */ ?>
						<img src="<?php echo esc_url( $mapped->icon ); ?>" />
					</span>
				<?php endif; ?>
			</div>
			<div class="product-footer">
				<div class="product-price-and-reviews-container">
					<div class="product-price-block">
						<?php if ( $mapped->is_free ) : ?>
							<span class="price"><?php esc_html_e( 'Free', 'woocommerce' ); ?></span>
						<?php else : ?>
							<span class="price">
								<?php
								echo wp_kses(
									$mapped->price,
									array(
										'span' => array(
											'class' => array(),
										),
										'bdi'  => array(),
									)
								);
								?>
							</span>
							<span class="price-suffix"><?php esc_html_e( 'per year', 'woocommerce' ); ?></span>
						<?php endif; ?>
					</div>
					<?php if ( ! empty( $mapped->reviews_count ) && ! empty( $mapped->rating ) ) : ?>
						<?php /* Show rating and the number of reviews */ ?>
						<div class="product-reviews-block">
							<?php for ( $index = 1; $index <= 5; ++$index ) : ?>
								<?php $rating_star_class = 'product-rating-star product-rating-star__' . self::get_star_class( $mapped->rating, $index ); ?>
								<div class="<?php echo esc_attr( $rating_star_class ); ?>"></div>
							<?php endfor; ?>
							<span class="product-reviews-count">(<?php echo (int) $mapped->reviews_count; ?>)</span>
						</div>
					<?php endif; ?>
				</div>
				<a class="button" href="<?php echo esc_url( $product_url ); ?>">
					<?php esc_html_e( 'View details', 'woocommerce' ); ?>
				</a>
			</div>
		</li>
		<?php
	}
}