Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Adjust styles
Browse files Browse the repository at this point in the history
  • Loading branch information
albarin committed Apr 29, 2022
1 parent 99fa814 commit 8498c27
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/BlockTypes/FeaturedProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ protected function render( $attributes, $content ) {
wp_kses_post( $product->get_price_html() )
);

$styles = $this->get_styles( $attributes );
$classes = $this->get_classes( $attributes );

$output = sprintf( '<div class="%1$s wp-block-woocommerce-featured-product" style="%2$s">', esc_attr( trim( $classes ) ), esc_attr( $styles ) );

$image_url = esc_url( $this->get_image_url( $attributes, $product ) );

$wrapper_styles = $this->get_wrapper_styles( $attributes, $image_url, $min_height );
$styles = $this->get_styles( $attributes, $image_url );
$classes = $this->get_classes( $attributes );

$output .= sprintf( '<div class="wc-block-featured-product__wrapper" style="%s">', esc_attr( $wrapper_styles ) );
$output = sprintf( '<div class="%1$s wp-block-woocommerce-featured-product">', esc_attr( trim( $classes ) ) );
$output .= sprintf( '<div class="wc-block-featured-product__wrapper" style="%s">', esc_attr( $styles ) );
$output .= $this->render_overlay( $attributes );

if ( ! $attributes['isRepeated'] ) {
Expand Down Expand Up @@ -201,14 +198,24 @@ private function render_overlay( $attributes ) {
/**
* Get the styles for the wrapper element (background image, color).
*
* @param array $attributes Block attributes. Default empty array.
* @param array $attributes Block attributes. Default empty array.
* @param string $image_url Url of the product image.
*
* @return string
*/
public function get_styles( $attributes ) {
public function get_styles( $attributes, $image_url ) {
$style = '';

$min_height = isset( $attributes['minHeight'] ) ? $attributes['minHeight'] : wc_get_theme_support( 'featured_block::default_height', 500 );
if ( $attributes['isRepeated'] ) {
$style .= "background-image: url($image_url);";
$style .= sprintf(
'background-position: %s%% %s%%;',
$attributes['focalPoint']['x'] * 100,
$attributes['focalPoint']['y'] * 100
);
}

$min_height = $attributes['minHeight'] ?? wc_get_theme_support( 'featured_block::default_height', 500 );

if ( isset( $attributes['minHeight'] ) ) {
$style .= sprintf( 'min-height:%dpx;', intval( $min_height ) );
Expand Down

0 comments on commit 8498c27

Please sign in to comment.