Plugin Directory

Changeset 3767494


Ignore:
Timestamp:
10/26/2026 11:39:47 PM (8 hours ago)
Author:
moiseh
Message:

Release 1.4.0

Location:
woocommerce-ajax-cart
Files:
26 added
5 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-ajax-cart/trunk/common/MHSettings.php

    r3757257 r3767494  
    198198
    199199            ?>
    200             <div class="wrap">
    201                 <div class="icon32">
    202                 <br />
    203                 </div>
    204                 <h2 class="nav-tab-wrapper">
     200            <div class="wrap mh-settings-wrap">
     201                <h1 class="mh-settings-title">
    205202                    <?php echo esc_html($title); ?>
    206                 </h2>
     203                </h1>
    207204                <?php if ( $displayPremiumTab ): ?>
    208205                    <?php $this->premium_alert_box(); ?>
    … …  
    248245            ?>
    249246            <?php $this->form_header() ?>
     247            <div class="mh-card">
    250248            <?php foreach ( $settings as $name => $conf ): ?>
    251                 <div class="conf">
    252                     <?php if ( empty($conf['depends_on']) ): ?>
     249                <?php if ( empty($conf['depends_on']) ): ?>
     250                    <div class="conf conf-<?php echo esc_attr($conf['type']); ?>">
    253251                        <?php $this->render_field($settings, $name, $conf) ?>
    254                     <?php endif; ?>
    255                 </div>
     252                    </div>
     253                <?php endif; ?>
    256254            <?php endforeach; ?>
     255            </div>
    257256            <?php do_action("mh_{$this->pluginAbbrev}_after_tab", $normalizedTab); ?>
    258257            <?php $this->form_footer() ?>
    … …  
    321320            <div class="mh-subconf">
    322321                <?php foreach ( $dependants as $name => $conf ): ?>
    323                     <?php $this->render_field($settings, $name, $conf); ?>
    324                     <br/>
     322                    <div class="conf conf-<?php echo esc_attr($conf['type']); ?>">
     323                        <?php $this->render_field($settings, $name, $conf); ?>
     324                    </div>
    325325                <?php endforeach; ?>
    326326            </div>
    … …  
    379379        public function form_footer() {
    380380            ?>
    381                 <hr/>
    382                 <input name="save" class="button-primary" type="submit" value="<?php echo esc_html__('Save settings', 'woocommerce-ajax-cart'); ?>" />
    383                 <?php do_action("mh_{$this->pluginAbbrev}_admin_buttons"); ?>
    384                 <input name="save" class="button" type="submit"
     381                <div class="mh-actions">
     382                    <input name="save" class="button button-primary" type="submit" value="<?php echo esc_html__('Save settings', 'woocommerce-ajax-cart'); ?>" />
     383                    <?php do_action("mh_{$this->pluginAbbrev}_admin_buttons"); ?>
     384                    <input name="save" class="button mh-reset" type="submit"
    385385                        value="<?php echo esc_html__('Reset all settings', 'woocommerce-ajax-cart'); ?>"
    386386                        onclick="return confirm('<?php echo esc_html__('Are you sure?', 'woocommerce-ajax-cart') ?>')"/>
     387                </div>
    387388            </form>
    388389            <?php
    … …  
    533534            ?>
    534535            <input type="hidden" name="<?php echo esc_attr($name) ?>" value="0" />
    535             <label>
     536            <label class="mh-check">
    536537                <input type="checkbox"
    537538                       <?php if ( $value === 'yes' ): ?>checked<?php endif; ?>
    538                        class="<?php echo esc_attr($class) ?>"
     539                       class="mh-switch <?php echo esc_attr($class) ?>"
    539540                       name="<?php echo esc_attr($name) ?>">
    540                 <?php echo esc_html($label); ?>
     541                <span><?php echo esc_html($label); ?></span>
    541542            </label>
    542543            <?php
    … …  
    547548           
    548549            ?>
    549             <?php echo esc_html($label); ?>:
     550            <span class="mh-label"><?php echo esc_html($label); ?></span>
    550551            <input type="text"
    551552                    value="<?php echo esc_attr($value); ?>"
    … …  
    559560           
    560561            ?>
    561             <?php echo esc_html($label); ?>:
     562            <span class="mh-label"><?php echo esc_html($label); ?></span>
    562563            <input type="number"
    563564                    value="<?php echo esc_attr($value); ?>"
    … …  
    572573           
    573574            ?>
    574             <?php echo esc_html($label); ?>:
     575            <span class="mh-label"><?php echo esc_html($label); ?></span>
    575576            <input type="color"
    576577                    value="<?php echo esc_attr($value); ?>"
    … …  
    583584           
    584585            ?>
    585             <?php echo esc_html($label); ?>:
     586            <span class="mh-label"><?php echo esc_html($label); ?></span>
    586587            <input type="date"
    587588                    value="<?php echo esc_attr($value); ?>"
    … …  
    594595           
    595596            ?>
    596             <?php echo esc_html($label); ?>:
     597            <span class="mh-label"><?php echo esc_html($label); ?></span>
    597598            <select name="<?php echo esc_attr($name) ?>">
    598599                <?php foreach ( (array) $options as $optVal => $optLabel ): ?>
    … …  
    609610           
    610611            ?>
    611             <br/>
    612             <?php echo esc_html($label); ?>:
    613             <br/>
     612            <span class="mh-label"><?php echo esc_html($label); ?></span>
    614613            <input type="hidden" name="<?php echo esc_attr($name); ?>" value=""/>
    615614            <select multiple="multiple" name="<?php echo esc_attr($name); ?>[]">
    … …  
    628627
    629628            ?>
    630             <?php echo esc_html( $label ); ?>: &nbsp;
     629            <span class="mh-label"><?php echo esc_html( $label ); ?></span>
     630            <span class="mh-chips">
    631631            <?php foreach ( $options as $key => $value ): ?>
    632                 <label><input
     632                <label class="mh-chip"><input
    633633                            name="<?php echo esc_attr($name); ?>[]"
    634634                            value="<?php echo esc_attr( $key ); ?>"
    635635                            <?php if ( in_array( $key, $values ) ): ?>checked="checked"<?php endif; ?>
    636636                            type="checkbox"/><?php echo esc_html( $value ); ?></label>
    637                 &nbsp;&nbsp;
    638637            <?php endforeach; ?>
     638            </span>
    639639            <?php
    640640        }
  • woocommerce-ajax-cart/trunk/common/assets/admin-settings.css

    r2385280 r3767494  
    1 label {
    2     line-height:28px;
    3 }
    4 
    51#footer-left,#footer-upgrade {
    62    display: none;
    73}
    84
    9 .mh-subconf {
    10     margin-left: 8px;
    11     padding-left: 20px;
    12     padding-bottom: 5px;
    13     border-left: 1px solid lightgray;
    14     border-bottom: 1px solid lightgray;
    15     margin-top: 5px;
     5/* Settings page: a card of rows — the label in one column, its control in the
     6   next; on/off settings are switches; a setting's sub-options sit in a tinted
     7   panel under it. */
     8.mh-settings-wrap {
     9    max-width: 1200px;
     10}
     11
     12.mh-settings-title {
     13    font-size: 23px;
     14    font-weight: 600;
     15    margin: 4px 0 14px;
    1616}
    1717
    1818.mh-settings-page {
    1919    font-size: 14px;
    20     margin: 1%;
     20    margin: 0;
     21    max-width: 920px;
     22}
     23
     24.mh-card {
     25    margin-top: 16px;
     26    background: #fff;
     27    border: 1px solid #dcdcde;
     28    border-radius: 8px;
     29    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
     30    padding: 6px 24px;
    2131}
    2232
    2333.mh-settings-page .conf {
     34    display: grid;
     35    grid-template-columns: 240px minmax(0, 1fr);
     36    align-items: center;
     37    column-gap: 20px;
     38    padding: 14px 0;
     39    border-bottom: 1px solid #f0f0f1;
     40}
     41
     42.mh-card > .conf:last-child {
     43    border-bottom: 0;
     44}
     45
     46.mh-settings-page .mh-label {
     47    font-weight: 600;
     48    color: #1d2327;
     49}
     50
     51.mh-settings-page .conf > select,
     52.mh-settings-page .conf > input[type=text],
     53.mh-settings-page .conf > input[type=number],
     54.mh-settings-page .conf > input[type=date] {
     55    justify-self: start;
     56    min-width: 220px;
     57    max-width: 100%;
     58    min-height: 36px;
     59    border-radius: 6px;
     60}
     61
     62.mh-settings-page .conf > select[multiple] {
     63    min-width: 260px;
     64    min-height: 96px;
    2465    padding: 4px;
     66}
     67
     68.mh-settings-page .conf > input[type=color] {
     69    justify-self: start;
     70    width: 56px;
     71    height: 34px;
     72    padding: 2px;
     73    border: 1px solid #8c8f94;
     74    border-radius: 6px;
     75    background: #fff;
     76    cursor: pointer;
     77}
     78
     79/* On/off settings: the whole row is the switch's label */
     80.mh-settings-page .conf-checkbox {
     81    display: block;
     82}
     83
     84.mh-check {
     85    display: flex;
     86    align-items: center;
     87    gap: 14px;
     88    cursor: pointer;
     89    line-height: 1.4;
     90}
     91
     92.mh-check > span {
     93    color: #1d2327;
     94}
     95
     96.mh-settings-page input.mh-switch[type=checkbox] {
     97    appearance: none;
     98    -webkit-appearance: none;
     99    flex: 0 0 auto;
     100    position: relative;
     101    width: 40px;
     102    height: 22px;
     103    margin: 0;
     104    border: 0;
     105    border-radius: 22px;
     106    background: #c3c4c7;
     107    box-shadow: none;
     108    cursor: pointer;
     109    transition: background .15s;
     110}
     111
     112.mh-settings-page input.mh-switch[type=checkbox]::before {
     113    content: '';
     114    position: absolute;
     115    top: 3px;
     116    left: 3px;
     117    width: 16px;
     118    height: 16px;
     119    margin: 0;
     120    border-radius: 50%;
     121    background: #fff;
     122    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
     123    transition: transform .15s;
     124}
     125
     126.mh-settings-page input.mh-switch[type=checkbox]:checked {
     127    background: var(--wp-admin-theme-color, #2271b1);
     128}
     129
     130.mh-settings-page input.mh-switch[type=checkbox]:checked::before {
     131    transform: translateX(18px);
     132}
     133
     134.mh-settings-page input.mh-switch[type=checkbox]:focus-visible {
     135    outline: 2px solid var(--wp-admin-theme-color, #2271b1);
     136    outline-offset: 2px;
     137}
     138
     139/* A setting's sub-options */
     140.mh-subconf {
     141    margin: 12px 0 0 54px;
     142    padding: 2px 18px;
     143    background: #f6f7f7;
     144    border-radius: 6px;
     145}
     146
     147.mh-subconf .conf {
     148    padding: 10px 0;
     149    border-bottom: 1px solid #e8e9ea;
     150    grid-template-columns: 186px minmax(0, 1fr);
     151}
     152
     153.mh-subconf .conf:last-child {
     154    border-bottom: 0;
     155}
     156
     157/* Several choices: chips */
     158.mh-chips {
     159    display: flex;
     160    flex-wrap: wrap;
     161    gap: 8px;
     162}
     163
     164.mh-chip {
     165    display: inline-flex;
     166    align-items: center;
     167    gap: 6px;
     168    padding: 5px 12px;
     169    border: 1px solid #c3c4c7;
     170    border-radius: 999px;
     171    background: #fff;
     172    cursor: pointer;
     173    line-height: 1.4;
     174}
     175
     176.mh-chip input[type=checkbox] {
     177    margin: 0;
     178}
     179
     180.mh-chip:has(input:checked) {
     181    border-color: var(--wp-admin-theme-color, #2271b1);
     182    background: #f0f6fc;
     183    color: var(--wp-admin-theme-color, #2271b1);
     184}
     185
     186/* Save / reset */
     187.mh-actions {
     188    display: flex;
     189    align-items: center;
     190    gap: 10px;
     191    margin-top: 18px;
     192}
     193
     194.mh-actions .button {
     195    min-height: 36px;
     196    padding: 0 18px;
     197    border-radius: 6px;
     198}
     199
     200.mh-actions .mh-reset {
     201    margin-left: auto;
     202}
     203
     204@media (max-width: 782px) {
     205    .mh-card {
     206        padding: 4px 14px;
     207    }
     208
     209    .mh-settings-page .conf,
     210    .mh-subconf .conf {
     211        grid-template-columns: minmax(0, 1fr);
     212        row-gap: 8px;
     213    }
     214
     215    .mh-subconf {
     216        margin-left: 0;
     217    }
    25218}
    26219
  • woocommerce-ajax-cart/trunk/i18n/languages/woocommerce-ajax-cart.pot

    r3757257 r3767494  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Ajax Cart for WooCommerce 1.3.28\n"
     5"Project-Id-Version: Ajax Cart for WooCommerce 1.4.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woocommerce-ajax-cart\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    … …  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2026-10-20T18:05:18+00:00\n"
     12"POT-Creation-Date: 2026-10-26T23:39:09+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.12.0\n"
    … …  
    1717#. Plugin Name of the plugin
    1818#: wooajaxcart.php
    19 #: wooajaxcart.php:44
     19#: wooajaxcart.php:46
    2020msgid "Ajax Cart for WooCommerce"
    2121msgstr ""
    … …  
    6969msgstr ""
    7070
    71 #: common/MHSettings.php:217
     71#: common/MHSettings.php:214
    7272msgid "Get PRO"
    7373msgstr ""
    … …  
    7878
    7979#. translators: %s: the plugin's review page
    80 #: common/MHSettings.php:396
     80#: common/MHSettings.php:397
    8181#, php-format
    8282msgid "If you liked this plugin, please help us <a href=\"%s\" target=\"_blank\">giving a 5-star rate</a> on WordPress.org :)"
    … …  
    8484
    8585#. translators: 1: the plugin's name, 2: the premium tab's address
    86 #: common/MHSettings.php:416
     86#: common/MHSettings.php:417
    8787#, php-format
    8888msgid "You're using a limited version of %1$s. For more features and better support, please <a href=\"%2$s\">consider the premium version</a>."
    8989msgstr ""
    9090
    91 #: common/MHSettings.php:516
     91#: common/MHSettings.php:517
    9292msgid "Features included in PRO version"
    9393msgstr ""
    9494
    95 #: common/MHSettings.php:523
     95#: common/MHSettings.php:524
    9696msgid "Buy on Gumroad"
    9797msgstr ""
    … …  
    102102msgstr ""
    103103
    104 #: wooajaxcart.php:58
     104#: wooajaxcart.php:60
    105105msgid "Display -/+ buttons around product quantity input"
    106106msgstr ""
    107107
    108 #: wooajaxcart.php:59
    109 #: wooajaxcart.php:65
    110 #: wooajaxcart.php:71
    111 #: wooajaxcart.php:80
    112 #: wooajaxcart.php:86
     108#: wooajaxcart.php:61
     109#: wooajaxcart.php:67
     110#: wooajaxcart.php:73
     111#: wooajaxcart.php:82
     112#: wooajaxcart.php:108
    113113msgid "General"
    114114msgstr ""
    115115
    116 #: wooajaxcart.php:64
     116#: wooajaxcart.php:66
    117117msgid "Show item quantity as select instead numeric field"
    118118msgstr ""
    119119
    120 #: wooajaxcart.php:70
     120#: wooajaxcart.php:72
    121121msgid "Items to show on select"
    122122msgstr ""
    123123
    124 #: wooajaxcart.php:79
     124#: wooajaxcart.php:81
    125125msgid "Show user confirmation when change item quantity to zero or empty"
    126126msgstr ""
    127127
    128 #: wooajaxcart.php:85
     128#: wooajaxcart.php:87
     129msgid "Enable the side cart: a cart drawer that slides in from the side, on every page but the cart and checkout"
     130msgstr ""
     131
     132#: wooajaxcart.php:88
     133#: wooajaxcart.php:94
     134#: wooajaxcart.php:101
     135msgid "Side cart"
     136msgstr ""
     137
     138#: wooajaxcart.php:93
     139msgid "Open the side cart when a product is added to the cart"
     140msgstr ""
     141
     142#: wooajaxcart.php:100
     143msgid "Show a floating cart button with the item count"
     144msgstr ""
     145
     146#: wooajaxcart.php:107
    129147msgid "AJAX timeout in milliseconds to refresh the cart on change"
    130148msgstr ""
    131149
    132 #: wooajaxcart.php:127
     150#: wooajaxcart.php:160
     151#: wooajaxcart.php:209
     152msgid "Are you sure you want to remove this item from cart?"
     153msgstr ""
     154
     155#: wooajaxcart.php:180
     156msgid "Open the cart"
     157msgstr ""
     158
     159#: wooajaxcart.php:187
     160msgid "Cart"
     161msgstr ""
     162
     163#: wooajaxcart.php:189
     164msgid "Your cart"
     165msgstr ""
     166
     167#: wooajaxcart.php:190
     168msgid "Close the cart"
     169msgstr ""
     170
     171#: wooajaxcart.php:208
    133172msgid "Updating..."
    134173msgstr ""
    135 
    136 #: wooajaxcart.php:128
    137 msgid "Are you sure you want to remove this item from cart?"
    138 msgstr ""
  • woocommerce-ajax-cart/trunk/readme.txt

    r3757257 r3767494  
    11=== Ajax Cart for WooCommerce ===
    22Contributors: moiseh
    3 Tags: woocommerce, ajax, cart, shipping
     3Tags: woocommerce, ajax, cart, side cart, quantity
    44Requires at least: 5.0
    55Tested up to: 7.1
    6 Stable tag: 1.3.28
     6Stable tag: 1.4.0
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
    99
    10 Updates the WooCommerce cart totals with AJAX as soon as a quantity changes, without clicking "Update cart".
     10AJAX cart for WooCommerce: totals update as soon as a quantity changes, plus a slide-in side cart that works with any theme.
    1111
    1212== Description ==
    1313
    14 Ajax Cart for WooCommerce changes the default behavior of the WooCommerce cart page: when a buyer changes the quantity of a product, the totals are recalculated right away with AJAX, without clicking the "Update cart" button.
     14Ajax Cart for WooCommerce makes buying smoother in two ways:
    1515
    16 This improves the user experience when purchasing a product. No other hacks/code/theme changes is needed, this functionality is added when the plugin is activated.
     16* **On the classic cart page** (the `[woocommerce_cart]` shortcode most stores and classic themes use), totals are recalculated with AJAX as soon as a quantity changes — no "Update cart" click — with -/+ buttons around the quantity.
     17* **A side cart** (optional): a cart drawer that slides in from the side when a product is added, with a floating cart button — on classic and block themes alike, on every page but the cart and checkout.
     18
     19On the newer **Cart block** (the default for stores created since WooCommerce 8.3), WooCommerce already updates quantities by itself; there the plugin adds a confirmation before an item is removed, and the side cart works the same.
     20
     21No other hacks, code or theme changes are needed: the features are active as soon as the plugin is.
    1722
    1823You can try and play with this plugin demonstration [clicking here](https://tastewp.com/new?pre-installed-plugin-slug=woocommerce%2Cwoocommerce-ajax-cart&redirect=plugins.php&ni=true)
    … …  
    2227Free version features:
    2328
    24 * Automatically reload and recalculate Cart using AJAX when quantity changes
     29* Automatically reload and recalculate the classic Cart using AJAX when quantity changes
    2530* Show -/+ buttons around item quantity on cart page
    2631* Show item quantity as select instead numeric field
    27 * Show user confirmation when change item quantity to zero
     32* Show user confirmation when change item quantity to zero — and, on the Cart block, before an item is removed
     33* Side cart: a cart drawer that slides in when a product is added, with a floating cart button and item count
    2834
    2935Premium version features:
    … …  
    3440* Option to lock quantity inputs to allow only change using plus and minus buttons
    3541* Update price vs quantity calculation automatically on Single Product pages
     42* Change quantities with -/+ buttons inside the side cart
     43* Free shipping progress bar ("Spend $12.00 more for free shipping") in the side cart, Mini-Cart, classic Cart and Cart block — the amount read from your free shipping method, or your own
     44* Undo a removed item on the Cart block
     45* Minimum, maximum and step for every product quantity, on the classic and the block cart
    3646
    3747If you looking for a related plugin with more complete features maybe you can try [Better Usability for WooCommerce](https://wordpress.org/plugins/woo-better-usability) plugin.
    … …  
    4858
    4959== Changelog ==
     60
     61= 1.4.0 =
     62* New: side cart — a cart drawer that slides in from the side when a product is added, with a floating cart button and item count (Settings > Side cart; off by default)
     63* New: on the Cart block, a confirmation before an item is removed (with the "confirmation when quantity goes to zero" setting)
     64* The description now says where each feature applies: the classic cart page, and what the Cart block already does by itself
     65* Changed: a cleaner settings page — the settings in a card, one row each with the label and its field aligned, on/off settings as switches, multiple choices as chips, a setting's sub-options in a panel under it, and Reset set apart from Save
    5066
    5167= 1.3.28 =
  • woocommerce-ajax-cart/trunk/wooajaxcart.php

    r3757257 r3767494  
    44Plugin URI: https://wordpress.org/plugins/woocommerce-ajax-cart/
    55Description: Updates the WooCommerce cart with AJAX as soon as a quantity changes — no "Update cart" click needed
    6 Version: 1.3.28
     6Version: 1.4.0
    77Author: Moises Heberle
    88Author URI: https://mhtec.org/contact/
    … …  
    2828    add_filter('woocommerce_cart_item_quantity', 'wac_filter_woocommerce_cart_item_quantity', 10, 3);
    2929    add_filter('wc_get_template', 'wac_get_template', 10, 5 );
     30    add_action('wp_footer', 'wac_side_cart_render');
     31    add_filter('woocommerce_add_to_cart_fragments', 'wac_side_cart_fragments');
    3032
    3133    add_action( 'before_woocommerce_init', function() {
    … …  
    8284            'default' => 'no',
    8385        );
     86        $arr['side_cart'] = array(
     87            'label' => __('Enable the side cart: a cart drawer that slides in from the side, on every page but the cart and checkout', 'woocommerce-ajax-cart'),
     88            'tab' => __('Side cart', 'woocommerce-ajax-cart'),
     89            'type' => 'checkbox',
     90            'default' => 'no',
     91        );
     92        $arr['side_cart_open_on_add'] = array(
     93            'label' => __('Open the side cart when a product is added to the cart', 'woocommerce-ajax-cart'),
     94            'tab' => __('Side cart', 'woocommerce-ajax-cart'),
     95            'type' => 'checkbox',
     96            'default' => 'yes',
     97            'depends_on' => 'side_cart',
     98        );
     99        $arr['side_cart_button'] = array(
     100            'label' => __('Show a floating cart button with the item count', 'woocommerce-ajax-cart'),
     101            'tab' => __('Side cart', 'woocommerce-ajax-cart'),
     102            'type' => 'checkbox',
     103            'default' => 'yes',
     104            'depends_on' => 'side_cart',
     105        );
    84106        $arr['ajax_timeout'] = array(
    85107            'label' => __('AJAX timeout in milliseconds to refresh the cart on change', 'woocommerce-ajax-cart'),
    … …  
    121143        $frontendData = wac_frontend_vars();
    122144        wp_localize_script( 'wooajaxcart', 'wooajaxcart', $frontendData );
     145
     146        if ( wac_side_cart_enabled() ) {
     147            // The drawer holds the Mini-Cart, which WooCommerce refreshes through its cart fragments.
     148            wp_enqueue_script('wc-cart-fragments');
     149            wp_enqueue_style('wac-side-cart', plugins_url('assets/wac-side-cart.css', plugin_basename(WAC_BASE_FILE)), array(), (string) filemtime($dir . 'assets/wac-side-cart.css'));
     150            wp_enqueue_script('wac-side-cart', plugins_url('assets/wac-side-cart.js', plugin_basename(WAC_BASE_FILE)), array('jquery'), (string) filemtime($dir . 'assets/wac-side-cart.js'), true);
     151            wp_localize_script('wac-side-cart', 'wac_side_cart', array(
     152                'open_on_add' => wac_option('side_cart_open_on_add'),
     153            ));
     154        }
     155
     156        // The Cart block updates quantities by itself; what it lacks is a confirmation before an item is removed.
     157        if ( is_cart() && wac_option('confirmation_zero_qty') == 'yes' && has_block('woocommerce/cart') ) {
     158            wp_enqueue_script('wac-cart-block', plugins_url('assets/wac-cart-block.js', plugin_basename(WAC_BASE_FILE)), array(), (string) filemtime($dir . 'assets/wac-cart-block.js'), true);
     159            wp_localize_script('wac-cart-block', 'wac_cart_block', array(
     160                'warn_remove_text' => __( 'Are you sure you want to remove this item from cart?', 'woocommerce-ajax-cart' ),
     161            ));
     162        }
     163    }
     164
     165    function wac_side_cart_enabled() {
     166        return ( wac_option('side_cart') == 'yes' ) && function_exists('WC') && ! is_cart() && ! is_checkout();
     167    }
     168
     169    function wac_side_cart_count() {
     170        return ( function_exists('WC') && WC()->cart ) ? (int) WC()->cart->get_cart_contents_count() : 0;
     171    }
     172
     173    // The drawer: WooCommerce's own Mini-Cart (refreshed by its cart fragments) in a panel that slides in.
     174    function wac_side_cart_render() {
     175        if ( ! wac_side_cart_enabled() ) {
     176            return;
     177        }
     178
     179        if ( wac_option('side_cart_button') == 'yes' ) {
     180            echo '<button type="button" class="wac-side-cart-toggle" aria-controls="wac-side-cart" aria-expanded="false" aria-label="' . esc_attr__( 'Open the cart', 'woocommerce-ajax-cart' ) . '">';
     181            echo '<svg class="wac-side-cart-icon" viewBox="0 0 24 24" width="26" height="26" aria-hidden="true" focusable="false"><path fill="currentColor" d="M7 18a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm10 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM7.2 14h9.9c.8 0 1.4-.4 1.7-1.1l3.1-6.4L20.1 5.6 17.2 12H8.1L4.3 4H1v2h2l3.6 7.6-1.4 2.4C4.5 17.3 5.5 19 7 19h12v-2H7l1.1-2z"/></svg>';
     182            echo '<span class="wac-side-cart-count">' . esc_html( wac_side_cart_count() ) . '</span>';
     183            echo '</button>';
     184        }
     185
     186        echo '<div class="wac-side-cart-overlay" hidden></div>';
     187        echo '<aside id="wac-side-cart" class="wac-side-cart" aria-hidden="true" aria-label="' . esc_attr__( 'Cart', 'woocommerce-ajax-cart' ) . '">';
     188        echo '<div class="wac-side-cart-header">';
     189        echo '<span class="wac-side-cart-title">' . esc_html__( 'Your cart', 'woocommerce-ajax-cart' ) . '</span>';
     190        echo '<button type="button" class="wac-side-cart-close" aria-label="' . esc_attr__( 'Close the cart', 'woocommerce-ajax-cart' ) . '">&times;</button>';
     191        echo '</div>';
     192        do_action('wac_side_cart_before_items');
     193        echo '<div class="widget_shopping_cart wac-side-cart-body"><div class="widget_shopping_cart_content">';
     194        woocommerce_mini_cart();
     195        echo '</div></div>';
     196        do_action('wac_side_cart_after_items');
     197        echo '</aside>';
     198    }
     199
     200    function wac_side_cart_fragments( $fragments ) {
     201        $fragments['span.wac-side-cart-count'] = '<span class="wac-side-cart-count">' . esc_html( wac_side_cart_count() ) . '</span>';
     202
     203        return $fragments;
    123204    }
    124205
Note: See TracChangeset for help on using the changeset viewer.