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

Commit

Permalink
Add to Cart Form: Fix broken styles for the block when using inside t…
Browse files Browse the repository at this point in the history
…he Single Product Block (#10282)

* Fix broken styles for Add to Cart Form block

* Fix PHP CS error
  • Loading branch information
thealexandrelara authored and gigitux committed Aug 2, 2023
1 parent 660e4aa commit cd6541e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Icon, button } from '@wordpress/icons';
*/
import metadata from './block.json';
import edit from './edit';
import './style.scss';
import './editor.scss';

const blockSettings = {
edit,
Expand Down
6 changes: 4 additions & 2 deletions src/BlockTypes/AddToCartForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ protected function render( $attributes, $content, $block ) {

$classname = $attributes['className'] ?? '';
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
$product_classname = $is_descendent_of_single_product_block ? 'product' : '';

$form = sprintf(
'<div class="wp-block-add-to-cart-form %1$s %2$s" style="%3$s">%4$s</div>',
'<div class="wp-block-add-to-cart-form %1$s %2$s %3$s" style="%4$s">%5$s</div>',
esc_attr( $classes_and_styles['classes'] ),
esc_attr( $classname ),
esc_attr( $product_classname ),
esc_attr( $classes_and_styles['styles'] ),
$product
);
Expand Down Expand Up @@ -181,7 +183,7 @@ protected function get_block_type_script( $key = null ) {
* @return null
*/
protected function get_block_type_style() {
return null;
return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] );
}

/**
Expand Down

0 comments on commit cd6541e

Please sign in to comment.