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
Allow usage of block notice templates when using classic themes #45164
Allow usage of block notice templates when using classic themes #45164
Conversation
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: |
ab384e9
to
c8b66b0
Compare
…mmerce-blocks, woocommerce
Test Results SummaryCommit SHA: aade6cc
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works OK for me, but left a couple of comments that need answers/addressing before approving. Thanks Niels
...mmerce-blocks/tests/e2e/tests/cart/cart-checkout-block-notices.shopper.classic_theme.spec.ts
Outdated
Show resolved
Hide resolved
Thanks for your review, @opr. I've addressed your feedback. Currently, there are two test failing. Nadir firstly mentioned these failing tests in p1709562740110129-slack-C03CPM3UXDJ and Bart mentioned that he'll be looking into them today. As these failing tests seem unrelated to this PR, you could go ahead and re-review the PR again, when you have time. |
...woocommerce-blocks/tests/e2e/bin/themes/storefront-child__block-notices-filter/functions.php
Show resolved
Hide resolved
...merce-blocks/tests/e2e/bin/themes/twentytwentyfour-child__block-notices-filter/functions.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better now Niels - there are some checks failing - https://github.com/woocommerce/woocommerce/actions/runs/8200519026/job/22427557137?pr=45164
Please could you address those and get a fresh review from someone else on Rubik as I'll be AFK for a week now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I bet this started out as something that would be tiny, and grew into a lot of changes and tests 😅
Nice work @nielslange, approving 👍🏼
Thanks for reviewing this PR, @wavvves. This PR indeed started small and then kept growing and growing. You can probably tell by the amount of test-related files. 😆 That said, thanks again for reviewing it. 🙌 |
The review feedback had been successfully addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I just ended up testing this and things works fine! great work with the tests Niels.
Very nice fix! @nielslange, Just one thing, if i do NOT opt in to show block notices in a classic theme wp_enqueue_style( 'wc-blocks-style' ); is still called on wp_head and there is no way to dequeue it.
To work around this it wouldn't it make sense to also check the conditionals in enqueue_notice_styles function? Simply replace:
with:
I know I'm late to the party, just hope someone reads this ;-) |
Thank you for reaching out, @PaulSchiretz. Initially, I placed the call Instead of: /**
* Replaces all notices with the new block-based notices.
*
* @return void
*/
public function enqueue_notice_styles() {
if ( wp_is_block_theme() || apply_filters( 'woocommerce_use_block_notices_in_classic_theme', false ) ) {
wp_enqueue_style( 'wc-blocks-style' );
}
} We could consider updating our approach to embed the action into the conditional statement: /**
* Initialize notice hooks.
*/
public function init() {
add_action(
'after_setup_theme',
function () {
/**
* Allow classic theme developers to opt-in to using block notices.
*
* @since 8.8.0
* @param bool $use_block_notices_in_classic_theme Whether to use block notices in classic themes.
* @return bool
*/
if ( wp_is_block_theme() || apply_filters( 'woocommerce_use_block_notices_in_classic_theme', false ) ) {
add_filter( 'wc_get_template', [ $this, 'get_notices_template' ], 10, 5 );
add_action( 'wp_head', [ $this, 'enqueue_notice_styles' ] );
}
}
);
add_filter( 'woocommerce_kses_notice_allowed_tags', [ $this, 'add_kses_notice_allowed_tags' ] );
} However, this change would require all merchants who are customizing classic notice templates to use block notice templates to add the following call to their sites, ensuring that the necessary styles are loaded: add_filter( 'woocommerce_use_block_notices_in_classic_theme', '__return_true' ); Considering the styles file is only 2.7kb, we decided against making this change to avoid the potential for disruption. Modifying this logic now could compel all merchants to implement the filter we discussed, which, while straightforward, might lead to temporary disruptions in the display of notices if overlooked, potentially causing frustration. Let me know if this makes sense to you, or if there are any other concerns we should address. |
@nielslange I see, makes total sense. Thanks for clarifiying this to me! I kind of went the other route, once the block templates where the default i tweaked my theme to incooperate the block templates then when the change was reversed i tweaked the classic templates to look like the block templates. Now that this is supported via hook i was wondering if i missed some spot once i saw the additional css file. Eather way as you also said, better to leave the css in than cause another confusion :-) Thanks for the quick clarification! |
Thank you for reaching out to clarify this, @PaulSchiretz. As for overwriting the notice templates, I posted Tutorial: Overriding notice templates a few weeks ago. You can either use the hook or manually overwrite the notice template files. That said, thanks again for reaching out, and please don't't hesitate to contact us if you have more questions or suggestions. 🙌 |
It works like a charm! Thanks @nielslange! |
Yeah! You're very welcome, @tiago-123. 🙌 |
Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #44538.
This PR enables merchants to display the blocks notice templates even when using classic themes. This can be accomplished by overwriting the template files or by using the following filter:
Apart from adjusting the display logic, I've also implemented e2e tests to ensure that this option remains working. In total, we're now having the following e2e tests regarding notice templates:
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
/wp-admin/admin.php?page=wc-settings&tab=advanced
and set the test page of the previous step as the Cart page./wp-admin/edit.php?post_type=shop_coupon
and create a coupon.Apart from the previous testing instructions, also have a look at the added and adjusted e2e tests and verify that all e2e tests are passing.
Screenshots
Changelog entry
Significance
Type
Message
Allow usage of block notice templates when using classic themes.
Comment