Skip to content

Commit 086d7e5

Browse files
authored
Merge pull request #327 from addonify/development
Plugin tags updated and cart icon shortcode added
2 parents cd5ca19 + 0b8fa5a commit 086d7e5

7 files changed

Lines changed: 206 additions & 23 deletions

File tree

README.txt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
=== Addonify Floating Cart For WooCommerce ===
22

33
Contributors: addonify
4-
Tags: cart, ajax, ajax cart, woocommerce, woocommerce cart, floating cart, side cart, woo cart, woocommerce floating cart, woocommerce side cart, fly cart
4+
Tags: cart, floating cart, side cart, mini cart, woocommerce cart,
55
Requires at least: 6.0.0
66
Requires PHP: 7.4
7-
Tested up to: 6.5.3
8-
Stable tag: 1.2.7
7+
Tested up to: 6.5.5
8+
Stable tag: 1.2.9
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111

@@ -88,14 +88,30 @@ Yes, we do have documentation guide. Please visit our [documentation site.](http
8888

8989
No, this plugin will not work without WooCommerce.
9090

91+
= Why does not side cart open when product is added into the cart from the product page? =
92+
93+
Because by default, when product is added into the cart from the product page, the product page is re-loaded.
94+
9195
= Does this plugin work with my theme? =
9296

93-
Yes, Addonify Floating Cart should work with all WordPress themes. If it does not work with your theme, let us know by [*creating an issue*](https://github.com/addonify/addonify-floating-cart/issues)
97+
If your theme is not a block theme, then yes, Addonify Floating Cart should work with your theme. If it does not work with your theme, let us know by [*creating an issue*](https://github.com/addonify/addonify-floating-cart/issues)
98+
99+
= Does this plugin work with WooCommerce blocks? =
100+
101+
If you are using WooCommerce blocks to display products, then this plugin might not work as expected. This plugin works well with classic WooCommerce product templates.
94102

95-
= On which page floating cart will not be visible? =
103+
= On which pages floating cart will not be visible? =
96104

97105
Floating cart button and sidebar shopping cart will not be visible on cart and checkout pages.
98106

107+
= Is there any shortcode to display a cart icon anywhere? =
108+
109+
Addonify Floating Cart has a shortcode that can be used to display a cart icon. The shortcode is as below:
110+
111+
```
112+
[afc_cart_icon id="my-id" class="css-classes" icon="icon-1" display_count="true" count_position="top-right"]
113+
```
114+
For more information on shorcode, follow the [documentation](https://docs.addonify.com/kb/floating-cart/)
99115

100116
== Installation ==
101117

@@ -116,6 +132,13 @@ Floating cart button and sidebar shopping cart will not be visible on cart and c
116132

117133
== Changelog ==
118134

135+
= 1.2.9 - 15 July, 2024 =
136+
137+
- Added: ShortCode for displaying cart icon.
138+
- Updated: Plugin tags.
139+
- Tested: Up to WordPress version 6.5.5.
140+
- Tested: Up to WooCommerce version 9.0.2.
141+
119142
= 1.2.8 - 23 May, 2024 ==
120143

121144
- Tested: WordPress version 6.5.3.

addonify-floating-cart.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* Plugin Name: Addonify Floating Cart For WooCommerce
1111
* Plugin URI: https://addonify.com/addonify-floating-cart
1212
* Description: Addonify Floating Cart is a free WooCommerce addon that adds an interactive sticky shopping cart on your website allowing your visitors no need to go to cart page to manage their cart items.
13-
* Version: 1.2.8
13+
* Version: 1.2.9
1414
* Requires at least: 6.0.0
1515
* Requires PHP: 7.4
16-
* Tested up to: 6.5.3
16+
* Tested up to: 6.5.5
1717
* Author: Addonify
1818
* Author URI: https://addonify.com/
1919
* License: GPLv2 or later
@@ -33,7 +33,7 @@
3333
* Start at version 1.0.0 and use SemVer - https://semver.org
3434
* Rename this for your plugin and update it as you release new versions.
3535
*/
36-
define( 'ADDONIFY_FLOATING_CART_VERSION', '1.2.8' );
36+
define( 'ADDONIFY_FLOATING_CART_VERSION', '1.2.9' );
3737
define( 'ADDONIFY_FLOATING_CART_BASENAME', plugin_basename( __FILE__ ) );
3838
define( 'ADDONIFY_FLOATING_CART_PATH', plugin_dir_path( __FILE__ ) );
3939
define( 'ADDONIFY_FLOATING_CART_DB_INITIALS', 'addonify_fc_' );
@@ -82,19 +82,17 @@ function run_addonify_floating_cart() {
8282

8383
$plugin = new Addonify_Floating_Cart();
8484
$plugin->run();
85-
} else {
86-
if ( version_compare( get_bloginfo( 'version' ), '6.5', '<' ) ) {
87-
add_action(
88-
'admin_notices',
89-
function() {
90-
?>
91-
<div class="notice notice-error is-dismissible">
92-
<p><?php echo esc_html__( 'Addonify Floating Cart requires WooCommerce in order to work.', 'addonify-floating-cart' ); ?></p>
93-
</div>
94-
<?php
95-
}
96-
);
97-
}
85+
} elseif ( version_compare( get_bloginfo( 'version' ), '6.5', '<' ) ) {
86+
add_action(
87+
'admin_notices',
88+
function () {
89+
?>
90+
<div class="notice notice-error is-dismissible">
91+
<p><?php echo esc_html__( 'Addonify Floating Cart requires WooCommerce in order to work.', 'addonify-floating-cart' ); ?></p>
92+
</div>
93+
<?php
94+
}
95+
);
9896
}
9997
}
10098
add_action( 'plugins_loaded', 'run_addonify_floating_cart' );

includes/misc-functions.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,42 @@ function addonify_floating_cart_get_cart_modal_toggle_button_icons() {
3434
}
3535

3636

37+
/**
38+
* Sanitizes SVG when rendering in the frontend.
39+
*
40+
* @since 1.0.0
41+
* @param string $svg SVG code.
42+
* @return string $svg Sanitized SVG code.
43+
*/
44+
function addonify_floating_cart_escape_svg( $svg ) {
45+
46+
$allowed_html = array(
47+
'svg' => array(
48+
'class' => true,
49+
'aria-hidden' => true,
50+
'aria-labelledby' => true,
51+
'role' => true,
52+
'xmlns' => true,
53+
'width' => true,
54+
'height' => true,
55+
'viewbox' => true,
56+
),
57+
'g' => array(
58+
'fill' => true,
59+
),
60+
'title' => array(
61+
'title' => true,
62+
),
63+
'path' => array(
64+
'd' => true,
65+
'fill' => true,
66+
),
67+
);
68+
69+
return wp_kses( $svg, $allowed_html );
70+
}
71+
72+
3773
if ( ! function_exists( 'addonify_floating_cart_default_strings' ) ) {
3874
/**
3975
* Translation ready strings displayed at the front-end.

public/assets/build/public.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/build/public.min.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/src/scss/components/_buttons.scss

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,43 @@ a.adfy__woofc-button.secondary,
356356
color: var(--adfy_woofc_base_link_color_hover);
357357
}
358358
}
359+
360+
361+
/*
362+
Shortcode Cart Icon
363+
*/
364+
.adfy_fc__woo-trigger-shortcode-button {
365+
366+
line-height: 1;
367+
position: relative;
368+
369+
.icon svg {
370+
height: 24px;
371+
width: 24px;
372+
}
373+
374+
.badge {
375+
align-items: center;
376+
background-color: var(--adfy_woofc_toggle_button_badge_background_color);
377+
border-radius: 20px;
378+
box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.1);
379+
color: var(--adfy_woofc_toggle_button_badge_text_color);
380+
display: inline-flex;
381+
font-size: 13px;
382+
height: 23px;
383+
justify-content: center;
384+
line-height: 1;
385+
position: absolute;
386+
top: -20px;
387+
transition: all 0.5s ease-in-out;
388+
width: 23px;
389+
390+
&.top-right {
391+
right: -15px;
392+
}
393+
394+
&.top-left {
395+
left: -15px;
396+
}
397+
}
398+
}

public/class-addonify-floating-cart-public.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function register_ajax_actions() {
169169

170170
add_action( 'wp_ajax_addonify_floating_cart_refresh_cart_fragments', array( $this, 'refresh_cart_fragments' ) );
171171
add_action( 'wp_ajax_nopriv_addonify_floating_cart_refresh_cart_fragments', array( $this, 'refresh_cart_fragments' ) );
172+
173+
add_shortcode( 'afc_cart_icon', array( $this, 'cart_toggle_button' ) );
172174
}
173175

174176

@@ -341,6 +343,90 @@ public function enqueue_scripts() {
341343
}
342344

343345

346+
/**
347+
* Callback function for `add_shortcode( 'afc_cart_toggle_button' )`.
348+
*
349+
* @since 1.2.7
350+
*
351+
* @param array $attrs Shortcode attributes.
352+
*/
353+
public function cart_toggle_button( $attrs ) {
354+
355+
if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
356+
return;
357+
}
358+
359+
$default_attrs = array(
360+
'icon' => 'icon_6',
361+
'class' => '',
362+
'display_items_count' => 'true',
363+
'items_count_position' => 'top-right',
364+
'id' => '',
365+
);
366+
367+
$shortcode_attrs = wp_parse_args( $attrs, $default_attrs );
368+
369+
$button_attributes = array(
370+
'class' => 'adfy_fc__woo-trigger-shortcode-button adfy__show-woofc',
371+
);
372+
373+
if ( isset( $shortcode_attrs['id'] ) && $shortcode_attrs['id'] ) {
374+
$button_attributes['id'] = esc_attr( $shortcode_attrs['id'] );
375+
}
376+
377+
if ( isset( $shortcode_attrs['class'] ) && $shortcode_attrs['class'] ) {
378+
$button_attributes['class'] .= ' ' . esc_attr( $shortcode_attrs['class'] );
379+
}
380+
381+
$button_svg_icons = addonify_floating_cart_get_cart_modal_toggle_button_icons();
382+
383+
ob_start();
384+
?>
385+
<a href="#" <?php echo wc_implode_html_attributes( $button_attributes ); // phpcs:ignore ?>>
386+
<?php
387+
if (
388+
isset( $shortcode_attrs['icon'] ) &&
389+
'none' !== $shortcode_attrs['icon'] &&
390+
array_key_exists( $shortcode_attrs['icon'], $button_svg_icons )
391+
) {
392+
?>
393+
<span class="icon">
394+
<?php echo addonify_floating_cart_escape_svg( $button_svg_icons[ $shortcode_attrs['icon'] ] ); //phpcs:ignore ?>
395+
</span>
396+
<?php
397+
}
398+
?>
399+
400+
<?php
401+
if ( isset( $shortcode_attrs['display_items_count'] ) && 'true' === $shortcode_attrs['display_items_count'] ) {
402+
403+
$cart_count = 0;
404+
if ( addonify_floating_cart_get_option( 'cart_badge_items_total_count' ) === 'total_products' ) {
405+
$cart_count = count( WC()->cart->get_cart_contents() );
406+
} else {
407+
$cart_count = WC()->cart->get_cart_contents_count();
408+
}
409+
410+
$count_positions = array(
411+
'top-right',
412+
'top-left',
413+
);
414+
415+
$count_position = (
416+
isset( $shortcode_attrs['items_count_position'] ) &&
417+
$shortcode_attrs['items_count_position'] &&
418+
in_array( $shortcode_attrs['items_count_position'], $count_positions, true )
419+
) ?
420+
$shortcode_attrs['items_count_position'] :
421+
'top-right';
422+
?>
423+
<span class="badge <?php echo esc_attr( $count_position ); ?>"><span class="adfy_woofc-badge-count"><?php echo esc_html( $cart_count ); ?></span></span>
424+
<?php } ?>
425+
</a>
426+
<?php
427+
return ob_get_clean();
428+
}
429+
344430
/**
345431
* Template for displaying sidebar cart toggle button.
346432
*

0 commit comments

Comments
 (0)