Skip to content

Add cart button integration for block and classic themes - #2928

Open
sazedul-haque wants to merge 6 commits into
devfrom
tutor-mini-cart
Open

sazedul-haque wants to merge 6 commits into
devfrom
tutor-mini-cart

Conversation

@sazedul-haque

Copy link
Copy Markdown
Collaborator

No description provided.

- Add Gutenberg cart button block for block theme integration
- Enable cart button usage in any block theme
- Add global cart button function for classic theme integration
- Add [tutor_cart_button] shortcode for theme developers
- Add customization options: show/hide icon, show/hide count, custom CSS class
- Add cart count badge with WooCommerce-style positioning and styling
@sazedul-haque
sazedul-haque requested a review from shewa12 July 27, 2026 04:31
@sazedul-haque sazedul-haque added the 4.1.0 Tutor v4.1.0 label Sep 15, 2026
$atts = array(
'show_icon' => 'true',
'show_count' => isset( $attributes['showCount'] ) ? $attributes['showCount'] : 'if_has_items',
'class' => isset( $attributes['customClass'] ) && ! empty( $attributes['customClass'] ) ? $attributes['customClass'] : 'cart-contents',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we are missing tutor prefix for classname

...(iconColor && { '--tutor-cart-icon-color': iconColor }),
} }
>
<svg

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use external svg file path?

'class' => isset( $attributes['customClass'] ) && ! empty( $attributes['customClass'] ) ? $attributes['customClass'] : 'cart-contents',
);

$shortcode = '[tutor_cart_button';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use sprintf

$shortcode = '[tutor_cart_button';

foreach ( $atts as $key => $value ) {
	$shortcode .= sprintf( ' %s="%s"', $key, esc_attr( $value ) );
}

$shortcode .= ']';

Comment thread classes/Shortcode.php
public function tutor_cart_button( $atts ) {
$atts = shortcode_atts(
array(
'class' => 'cart-contents',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default should be start with tutor- prefix


ob_start();
?>
<a class="<?php echo esc_attr( $args['class'] ); ?>" href="<?php echo esc_url( $cart_url ); ?>"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This element only has an option to show or hide the icon. If show_icon is false, the element should not be rendered.

return 0;
}

$cart_items = tutor_get_cart_items();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return

tutor_utils()->count( tutor_get_cart_items() );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.1.0 Tutor v4.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants