Block.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\CartMenuButton; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\BaseBlock; |
| 6 | |
| 7 | /** |
| 8 | * Cart Menu Button CTA 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 | $form = \SureCart::cart()->getForm(); |
| 21 | $mode = \SureCart::cart()->getMode(); |
| 22 | |
| 23 | // Stop if no form or mode found as for deletion. |
| 24 | if ( empty( $form->ID ) || empty( $mode ) ) { |
| 25 | return ''; |
| 26 | } |
| 27 | |
| 28 | // Don't render if the cart is disabled. |
| 29 | if ( ! \SureCart::cart()->isCartEnabled() ) { |
| 30 | return ''; |
| 31 | } |
| 32 | |
| 33 | $icon = '<sc-icon name="' . esc_attr( $attributes['cart_icon'] ?? 'shopping-bag' ) . '"></sc-icon>'; |
| 34 | |
| 35 | ob_start(); ?> |
| 36 | |
| 37 | <a href="<?php echo esc_attr( \SureCart::pages()->url( 'checkout' ) ); ?>" class="menu-link <?php echo esc_attr( $this->getClasses( $attributes ) ); ?>" style="<?php echo esc_attr( $this->getStyles( $attributes ) ); ?> line-height: 0;"> |
| 38 | <sc-cart-button |
| 39 | cart-menu-always-shown='<?php echo esc_attr( ! empty( $attributes['cart_menu_always_shown'] ) ? 'true' : 'false' ); ?>' |
| 40 | form-id='<?php echo esc_attr( $form->ID ); ?>' |
| 41 | mode='<?php echo esc_attr( $mode ); ?>'> |
| 42 | <?php |
| 43 | /** |
| 44 | * Allow filtering of the cart menu icon. |
| 45 | * |
| 46 | * @param string $icon The icon. |
| 47 | * @param string $mode The icon position. |
| 48 | */ |
| 49 | echo wp_kses_post( apply_filters( 'sc_cart_menu_icon', $icon, 'block' ) ); ?> |
| 50 | </sc-cart-button> |
| 51 | </a> |
| 52 | |
| 53 | <?php |
| 54 | return ob_get_clean(); |
| 55 | } |
| 56 | } |
| 57 |