Block.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\ProductCollectionTitle; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\BaseBlock; |
| 6 | |
| 7 | /** |
| 8 | * Product Title Block |
| 9 | */ |
| 10 | class Block extends BaseBlock { |
| 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 | $collection = get_query_var( 'surecart_current_collection' ); |
| 21 | |
| 22 | if ( empty( $collection ) ) { |
| 23 | $term = get_queried_object(); |
| 24 | if ( empty( $term ) || empty( $term->term_id ) ) { |
| 25 | return ''; |
| 26 | } |
| 27 | |
| 28 | $collection = sc_get_collection( $term->term_id ); |
| 29 | |
| 30 | if ( empty( $collection ) ) { |
| 31 | return ''; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return sprintf( |
| 36 | '<%1$s class="%2$s" style="%3$s"> |
| 37 | %4$s |
| 38 | </%1$s>', |
| 39 | 'h' . (int) ( $attributes['level'] ?? 1 ), |
| 40 | esc_attr( $this->getClasses( $attributes ) . ' surecart-block collection-title' ), |
| 41 | esc_attr( $this->getStyles( $attributes ) ), |
| 42 | $collection->name |
| 43 | ); |
| 44 | } |
| 45 | } |
| 46 |