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

Fine-tune the Add to cart form block #8482

Merged
merged 10 commits into from
Feb 24, 2023
1 change: 1 addition & 0 deletions assets/js/atomic/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ import './product-elements/category-list';
import './product-elements/tag-list';
import './product-elements/stock-indicator';
import './product-elements/add-to-cart';
import './product-elements/add-to-cart-form';
import './product-elements/product-image-gallery';
import './product-elements/product-details';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* External dependencies
*/
import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils';
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';
import { Icon, button } from '@wordpress/icons';

/**
* Internal dependencies
*/
import metadata from './block.json';
import edit from './edit';

registerBlockSingleProductTemplate( {
registerBlockFn: () => {
// @ts-expect-error: `registerBlockType` is a function that is typed in WordPress core.
registerBlockType( metadata, {
icon: {
src: (
<Icon
icon={ button }
className="wc-block-editor-components-block-icon"
/>
),
},
edit,
save() {
return null;
},
} );
},
unregisterBlockFn: () => {
unregisterBlockType( metadata.name );
},
blockName: metadata.name,
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.wp-block-add-to-cart-form {
.woocommerce-Price-amount.amount,
.woocommerce-grouped-product-list-item__price del {
font-size: var(--wp--preset--font-size--large);
}
}
29 changes: 0 additions & 29 deletions assets/js/blocks/add-to-cart-form/index.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions assets/js/blocks/add-to-cart-form/style.scss

This file was deleted.

9 changes: 8 additions & 1 deletion src/BlockTypes/AddToCartForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function render( $attributes, $content, $block ) {
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );

return sprintf(
'<div class="woocommerce wc-block-add-to-cart-form %1$s %2$s" style="%3$s"><div class="product type-product"><div class="summary entry-summary">%4$s</div></div></div>',
'<div class="wp-block-add-to-cart-form %1$s %2$s" style="%3$s">%4$s</div>',
esc_attr( $classes_and_styles['classes'] ),
esc_attr( $classname ),
esc_attr( $classes_and_styles['styles'] ),
Expand All @@ -64,4 +64,11 @@ protected function render( $attributes, $content, $block ) {
protected function get_block_type_script( $key = null ) {
return null;
}

/**
* It isn't necessary register block assets because it is a server side block.
*/
protected function register_block_type_assets() {
return null;
}
}