Block.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\ProductCollectionDescription; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\BaseBlock; |
| 6 | |
| 7 | /** |
| 8 | * Product Title Block |
| 9 | */ |
| 10 | class Block extends BaseBlock { |
| 11 | /** |
| 12 | * Keep track of the instance number of this block. |
| 13 | * |
| 14 | * @var integer |
| 15 | */ |
| 16 | public static $instance; |
| 17 | |
| 18 | /** |
| 19 | * Render the block |
| 20 | * |
| 21 | * @param array $attributes Block attributes. |
| 22 | * @param string $content Post content. |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | public function render( $attributes, $content ) { |
| 27 | $collection = get_query_var( 'surecart_current_collection' ); |
| 28 | |
| 29 | if ( empty( $collection ) ) { |
| 30 | $term = get_queried_object(); |
| 31 | if ( empty( $term ) || empty( $term->term_id ) ) { |
| 32 | return ''; |
| 33 | } |
| 34 | |
| 35 | $collection = sc_get_collection( $term->term_id ); |
| 36 | |
| 37 | if ( empty( $collection ) ) { |
| 38 | return ''; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) ); |
| 43 | |
| 44 | return ( |
| 45 | '<div ' . $wrapper_attributes . '>' . |
| 46 | wp_kses_post( $collection->description ) . |
| 47 | '</div>' |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 |