Skip to content

Conversation

Axos11
Copy link
Contributor

@Axos11 Axos11 commented May 27, 2025

  • Refactors the mini-cart to use fragments for more granular updates,
  • improves the user experience, and prevents full page reloads.
  • Adds support for displaying WooCommerce notices as toasts in the mini-cart and implements a filter to enable or disable toasts.
  • Improves quantity update functionality in the mini-cart, including validation and handling of cart updates and error messages.
  • Show removal of products as well.
  • Splits mini-cart template into separate files

New Filters

Docs

  • Filter & Action Hooks
    • Reference List
    • Examples
  • WooCommerce
  • Release Post

file: ajax-cart.php

/**
 * If set to 'the notifications section in the minicart will be changed to a toast based model to save space
 * default: false
 */
add_filter('bootscore/woocommerce/notifications/mini-cart/use_toasts', '__return_true');

file: ajax-cart.php

/**
 * Enables you to alter the cart Fragments on qty update before they are transmitted back to the frontend via ajax,
The second variable can either be success or error, depending if the update was successfull or failed.
 */
$response_item['fragments_replace'] = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/fragments/replace', $response_item['fragments_replace'], 'error');

file: ajax-cart.php

/**
 * Enables you to alter the complete response item that is transmitted via ajax but with a WC-cart Session state before the qty update is applied
 */
$response_item = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/response/before-update', $response_item, $cart_item_key);

file: ajax-cart.php

/**
 * Enables you to alter the complete response item that is transmitted via ajax but with a WC-cart Session state after the qty update is applied.
 */
$response_item = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/response/after-update', $response_item, $updated_item, $cart_item_key, $cart_content_after, $cart_content_before);

file: ajax-cart.php

/**
 * Adds a custom validation of the update process after the standard woocommerce one. If false is returned. the qty won't be updated.
 */
$passed_validation_qty_update = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/validate-update', true, $cart_item_key, $cart_content_before[$cart_item_key], $qty);

file: ajax-cart.php

/**
 * If returned true, forces a complete fragment refresh that will reload the whole ajax cart like stock woocommerce does. That can come in handy if some plugin conflicts or specific products have an issue with partial refreshs.
 * default: false
 */
$response_item['force_fragments_refresh'] = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/response/force-full-refresh', false, $response_item, $cart_item_key, $qty);

file: ajax-cart.php

/**
 * Change the position of the toast container
 */
function change_toasts_container_position() {
  return 'position-fixed bottom-0 start-0 p-3 px-4';
}
add_filter('bootscore/class/woocommerce/toast-container', 'change_toasts_container_position');

Axos11 added 13 commits May 26, 2025 15:42
Refactors the mini-cart template into three separate files
(item, footer, main) to enable independent AJAX calls for each
section. This improves modularity and allows for more efficient
updates to specific parts of the mini-cart.
Refactors the mini-cart to use fragments for more granular updates,
improves the user experience, and prevents full page reloads.

Adds support for displaying WooCommerce notices as toasts in the
mini-cart and implements a filter to enable or disable toasts.

Improves quantity update functionality in the mini-cart, including
validation and handling of cart updates and error messages.

Adds a container for WooCommerce messages for improved handling and
animation capabilities.

Show removal of products as well.
Updates the CSS selector used to refresh the total amount in the mini-cart, ensuring it targets the correct element after recent template changes.
Implements button loader for products in the loop using a PHP filter instead of JavaScript. Should improve performance and cacheability.
Streamlines quantity button handling by using filters for enabling/disabling buttons, removing the need for JavaScript validation.

Improves cart updating process by consolidating quantity update logic into a single function.

Addresses issues with quantity input focus and blur events, ensuring proper value handling and validation.
Reimplements the quantity button logic for single product pages and legacy cart forms, ensuring correct value updates and button state management.

Refactors the existing quantity button handling to differentiate between single product/legacy cart forms and the AJAX mini-cart, preventing conflicts and ensuring proper functionality in both contexts.
Refactors the mini-cart template into three separate files
(item, footer, main) to enable independent AJAX calls for each
section. This improves modularity and allows for more efficient
updates to specific parts of the mini-cart.
Refactors the mini-cart to use fragments for more granular updates,
improves the user experience, and prevents full page reloads.

Adds support for displaying WooCommerce notices as toasts in the
mini-cart and implements a filter to enable or disable toasts.

Improves quantity update functionality in the mini-cart, including
validation and handling of cart updates and error messages.

Adds a container for WooCommerce messages for improved handling and
animation capabilities.

Show removal of products as well.
Updates the CSS selector used to refresh the total amount in the mini-cart, ensuring it targets the correct element after recent template changes.
Implements button loader for products in the loop using a PHP filter instead of JavaScript. Should improve performance and cacheability.
Streamlines quantity button handling by using filters for enabling/disabling buttons, removing the need for JavaScript validation.

Improves cart updating process by consolidating quantity update logic into a single function.

Addresses issues with quantity input focus and blur events, ensuring proper value handling and validation.
Reimplements the quantity button logic for single product pages and legacy cart forms, ensuring correct value updates and button state management.

Refactors the existing quantity button handling to differentiate between single product/legacy cart forms and the AJAX mini-cart, preventing conflicts and ensuring proper functionality in both contexts.
@crftwrk crftwrk added this to v6.2.0 May 27, 2025
@crftwrk crftwrk moved this to In Progress in v6.2.0 May 27, 2025
@crftwrk crftwrk added documentation Improvements or additions to documentation WooCommerce ajax cart feature labels May 27, 2025
Consolidates quantity button handling into woocommerce.js
for single product and legacy cart forms.

Disables toast messages in the mini cart and reverts to normal messages.
@crftwrk
Copy link
Member

crftwrk commented May 27, 2025

Looks great!

We should fix the translations at the end https://www.vdzev.de/service/broschueren-und-arbeitsmaterial/#anlagentechnik-oder-heizungsanlagen

Bildschirmfoto 2025-05-27 um 12 15 03 Bildschirmfoto 2025-05-27 um 12 11 59

@Axos11
Copy link
Contributor Author

Axos11 commented May 27, 2025

i would do that in one step with the js extraction.

@Axos11
Copy link
Contributor Author

Axos11 commented May 28, 2025

Filters in ajax-cart.php

file: ajax-cart.php
function: If set to 'the notifications section in the minicart will be changed to a toast based model to save space
default: deactivated
to activate: add_filter('bootscore/woocommerce/notifications/mini-cart/use_toasts', '__return_true');

file: ajax-cart.php
function: Enables you to alter the cart Fragments on qty update before they are transmitted back to the frontend via ajax,
The second variable can either be success or error, depending if the update was successfull or failed.
$response_item['fragments_replace'] = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/fragments/replace', $response_item['fragments_replace'], 'error');

file: ajax-cart.php
function: Enables you to alter the complete response item that is transmitted via ajax but with a WC-cart Session state before the qty update is applied
$response_item = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/response/before-update', $response_item, $cart_item_key);

file: ajax-cart.php
function: Enables you to alter the complete response item that is transmitted via ajax but with a WC-cart Session state after the qty update is applied.
$response_item = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/response/after-update', $response_item, $updated_item, $cart_item_key, $cart_content_after, $cart_content_before);

file: ajax-cart.php
function: Adds a custom validation of the update process after the standard woocommerce one. If false is returned. the qty won't be updated.
$passed_validation_qty_update = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/validate-update', true, $cart_item_key, $cart_content_before[$cart_item_key], $qty);

file: ajax-cart.php
function: If returned true, forces a complete fragment refresh that will reload the whole ajax cart like stock woocommerce does. That can come in handy if some plugin conflicts or specific products have an issue with partial refreshs.
default: false
$response_item['force_fragments_refresh'] = apply_filters('bootscore/woocommerce/ajax-cart/update-qty/response/force-full-refresh', false, $response_item, $cart_item_key, $qty);

file: ajax-cart.php
function: if you want to change the positioning of the toast container in the ajax-cart you can do so by just changing the class.
default: 'position-fixed top-0 end-0 p-3 px-4'
apply_filters('bootscore/class/woocommerce/toast-container', 'position-fixed top-0 end-0 p-3 px-4')

Axos11 added 3 commits May 28, 2025 08:58
Renames filters to align with Bootscore naming conventions,
improving code maintainability and readability.
Moves AJAX cart JavaScript to an external file for better organization and maintainability.

Fixes quantity button behavior in the mini-cart, ensuring correct increment/decrement operations.

Removes duplicated line of code and updates translation strings.
Disables the quantity input field when it is set to readonly, improving the user experience by preventing interaction with a non-editable field.

Improves the display when only one item remains in stock by ensuring the quantity buttons are correctly disabled.
@crftwrk crftwrk self-requested a review May 29, 2025 08:54
Copy link
Member

@crftwrk crftwrk left a comment

Choose a reason for hiding this comment

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

Nice job! 🙏

@crftwrk crftwrk merged commit e3816ae into bootscore:main May 29, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in v6.2.0 May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ajax cart documentation Improvements or additions to documentation feature WooCommerce
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants