Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add totalValue filter #45170

Merged
merged 8 commits into from Mar 12, 2024
Merged

Add totalValue filter #45170

merged 8 commits into from Mar 12, 2024

Conversation

nielslange
Copy link
Member

@nielslange nielslange commented Feb 27, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #42004.
Closes #45172.

This PR adds the totalValue filter to wrap the total price on the Cart and Checkout blocks. This filter is needed for plugins such as Pre-Orders. It follows the same patterns of the following existing filters:

  • cartItemPrice
  • subtotalPriceFormat
  • saleBadgePriceFormat

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Install and activate the Simple Custom CSS and JS plugin.
  2. Go to /wp-admin/edit.php?post_type=custom-css-js and add the following code snippet:
const { registerCheckoutFilters } = window.wc.blocksCheckout;

const modifyTotalsPrice = ( defaultValue, extensions, args, validation ) => {
	return "Pay <price/> now";
};

registerCheckoutFilters( 'my-extension', {
	totalValue: modifyTotalsPrice,
} );

Important

Make sure to run the script in the footer as it requires other dependencies to load first.

  1. Go to the frontend and add a product to the cart.
  2. Go to the cart page and verify that the total price shows as Pay ... now.
  3. Go to the checkout page and verify that the total price shows as Pay ... now.
  4. Remove <price/> from the code snippet and repeat steps 4. and 5.
  5. Verify that the error message Error: Returned value must include <price/>, you passed "Pay now" is visible.

Screenshots

Cart block:

Screenshot 2024-02-27 at 20 21 30
Checkout block:

Screenshot 2024-02-27 at 20 22 41

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Add totalValue filter.

Comment

@nielslange nielslange closed this Feb 27, 2024
@nielslange nielslange reopened this Feb 27, 2024
Copy link
Contributor

github-actions bot commented Feb 27, 2024

Test Results Summary

Commit SHA: 28c20ef

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 39s
E2E Tests335001603518m 32s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 11, 2024
@nielslange nielslange marked this pull request as ready for review March 11, 2024 10:59
@woocommercebot woocommercebot requested review from a team and wavvves and removed request for a team March 11, 2024 11:00
Copy link
Contributor

Hi @wavvves,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@wavvves
Copy link
Contributor

wavvves commented Mar 11, 2024

Hi @nielslange, I'm seeing some failing tests related to Totals that seem related. In the meantime I'll start reviewing the changes 👍🏼

@nielslange
Copy link
Member Author

Hi @nielslange, I'm seeing some failing tests related to Totals that seem related. In the meantime I'll start reviewing the changes 👍🏼

Thanks for reviewing this PR, @wavvves. I've looked into the failing JS unit tests, and it turned out they were related to some CSS classes and HTML markup changes. I've addressed these issues and all tests are now passing. Would you mind reviewing this PR again?

Copy link
Contributor

@wavvves wavvves left a comment

Choose a reason for hiding this comment

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

Nice work @nielslange, tested out and everything seems to be working as expected!

@nielslange
Copy link
Member Author

Nice work @nielslange, tested out and everything seems to be working as expected!

Thanks for reviewing this PR again, and thanks for calling out the failing JS unit tests. Somehow, I missed them initially, thinking they would be failing due to another PR, while this PR was causing them to fail. 🙈

@nielslange nielslange merged commit 6b07ca4 into trunk Mar 12, 2024
61 checks passed
@nielslange nielslange deleted the add/42004-totalValue-filter branch March 12, 2024 17:42
@github-actions github-actions bot added this to the 8.8.0 milestone Mar 12, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Mar 12, 2024
@alvarothomas alvarothomas added needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Mar 12, 2024
@alopezari alopezari added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. and removed needs: internal testing Indicates if the PR requires further testing conducted by Solaris labels Mar 13, 2024
Konamiman pushed a commit that referenced this pull request Mar 13, 2024
* Add totalValue filter

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

* Remove nowrap to prevent text overflow

* Start docs for ‘totalValue’ filter

* Fix *.md lint issues

* Ignore .md lint errors for now

* Update code example and add screenshots

* Fix failing JS unit tests

---------

Co-authored-by: github-actions <github-actions@github.com>
@nigeljamesstevenson nigeljamesstevenson added the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. release: highlight Issues that have a high user impact and need to be discussed/paid attention to. status: analysis complete Indicates if a PR has been analysed by Solaris team: Rubik
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document totalValue filter [Enhancement]: Add a totalValue Checkout Block filter to modify total value
5 participants