Block.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\Product\Quantity; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\Product\ProductBlock; |
| 6 | |
| 7 | /** |
| 8 | * Product Title Block |
| 9 | */ |
| 10 | class Block extends ProductBlock { |
| 11 | /** |
| 12 | * Render the block |
| 13 | * |
| 14 | * @param array $attributes Block attributes. |
| 15 | * @param string $content Post content. |
| 16 | * |
| 17 | * @return string |
| 18 | */ |
| 19 | public function render( $attributes, $content ) { |
| 20 | $product = $this->getProductAndSetInitialState( $attributes['id'] ?? '' ); |
| 21 | if ( empty( $product->id ) ) { |
| 22 | return ''; |
| 23 | } |
| 24 | |
| 25 | $attributes = get_block_wrapper_attributes( |
| 26 | [ |
| 27 | 'label' => esc_attr( $attributes['label'] ?? '' ), |
| 28 | 'product-id' => esc_attr( $product->id ), |
| 29 | 'class' => esc_attr( $this->getClasses( $attributes ) ), |
| 30 | 'style' => esc_attr( $this->getStyles( $attributes ) ), |
| 31 | ] |
| 32 | ); |
| 33 | |
| 34 | return wp_sprintf( |
| 35 | '<sc-product-quantity %1$s></sc-product-quantity>', |
| 36 | $attributes |
| 37 | ); |
| 38 | } |
| 39 | } |
| 40 |