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

Commit

Permalink
Add align to wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Oct 18, 2023
1 parent 9128af9 commit a43da7d
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/BlockTypes/ClassicShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,46 @@ protected function render( $attributes, $content, $block ) {
}

if ( 'cart' === $attributes['shortcode'] ) {
return $this->render_cart();
return $this->render_cart( $attributes );
}

if ( 'checkout' === $attributes['shortcode'] ) {
return $this->render_checkout();
return $this->render_checkout( $attributes );
}

return "You're using the ClassicShortcode block";
}

/**
* Get the list of classes to apply to this block.
*
* @param array $attributes Block attributes. Default empty array.
* @return string space-separated list of classes.
*/
protected function get_container_classes( $attributes = array() ) {
$classes = array( 'wp-block-group' );

if ( isset( $attributes['align'] ) ) {
$classes[] = "align{$attributes['align']}";
}

return implode( ' ', $classes );
}

/**
* Render method for rendering the cart shortcode.
*
* @param array $attributes Block attributes.
* @return string Rendered block type output.
*/
protected function render_cart() {
protected function render_cart( $attributes ) {
if ( ! isset( WC()->cart ) ) {
return '';
}

ob_start();

echo '<div class="wp-block-group">';
echo '<div class="' . esc_attr( $this->get_container_classes( $attributes ) ) . '">';
WC_Shortcode_Cart::output( array() );
echo '</div>';

Expand All @@ -82,16 +99,17 @@ protected function render_cart() {
/**
* Render method for rendering the checkout shortcode.
*
* @param array $attributes Block attributes.
* @return string Rendered block type output.
*/
protected function render_checkout() {
protected function render_checkout( $attributes ) {
if ( ! isset( WC()->cart ) ) {
return '';
}

ob_start();

echo '<div class="wp-block-group">';
echo '<div class="' . esc_attr( $this->get_container_classes( $attributes ) ) . '">';
WC_Shortcode_Checkout::output( array() );
echo '</div>';

Expand Down

0 comments on commit a43da7d

Please sign in to comment.