-
Notifications
You must be signed in to change notification settings - Fork 221
Cart and Checkout Page Migration: Inherit Page template and fix rendering #10375
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThe
This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +574 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
Nice find @mikejolley, I tested it and I works ok, I'm approving this if you make it ready 👍🏼 There is another styling issue regarding the content's container width that happens on migration, and makes the cart/checkout narrower on templates than on pages: For TT3 for example, the width is a calculation, but the template defaults at 650px. This can be edited and fixed by the merchant here: Do you think this should be tackled along this fix, or should it be tackled along the other migration issue later? Both can be fixed manually by the merchant so urgency is lower than this one. |
I tried to reproduce this but I couldn't, even after following your steps in #10357 (comment). Since Paulo has verified it, I'll assume I'm missing something but I won't spend more time on trying to figure it out. |
$settings['original_render_callback'] = $settings['render_callback']; | ||
$settings['render_callback'] = function( $attributes, $content ) use ( $settings ) { | ||
// The shortcode has already been rendered, so look for the cart/checkout HTML. | ||
if ( strstr( $content, 'woocommerce-cart-form' ) || strstr( $content, 'woocommerce-checkout-form' ) ) { |
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.
It's checking for the classnames used by the cart/checkout forms so as only to target those shortcodes.
return $content; | ||
} | ||
|
||
$render_callback = $settings['original_render_callback']; |
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.
Falls back to original renderer for other shortcodes.
|
||
if ( $existing_page_template && ! empty( $existing_page_template->content ) ) { | ||
// Massage the original content into something we can use. Replace post content with a group block. | ||
$pattern = '/(<!--\s*)wp:post-content(.*?)(\/-->)/'; |
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.
Replaces the original wp:post-content
block with the actual page content, wrapped in a group. Layout props are inherited.
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.
Checkout and Cart shortcodes are migrated as expected.
I noticed some issues with other shortcodes tho, but we should not be the ones fixing those. The issue should be fixed upstream. I'm just sharing my findings in this comments.
Approving the PR.
Great work @mikejolley . Awesome that you also fixed the template parts bug
…ring (#10375) * Change shortcode block render callback * Inherit template from original "page" template
* Fix: WooCommerce Blocks causing malfunction of the navigation block on WordPress 6.3 (#10388) * Make sure the revert button is registered and enqueued for usage exclusively in the site editor. * Register and enqueue the styles for the revert button. * Rename the files. * Revert "Rename the file renames." This reverts commit c0330ce. * Add plugin-proposal-optional-chaining to the WebPack plugins config. * Rename the files. * Remove unnecessary dependencies as those are already provided via : more specifically, get_script_data. * Address CR. * Cart and Checkout Page Migration: Inherit Page template and fix rendering (#10375) * Change shortcode block render callback * Inherit template from original "page" template * Check if WordPress version is higher than 6.2.2 to make Products block compatible with Gutenberg 16+ (#10360) * Check if WordPress version is higher than 6.2.2 to make Products block compatible with Gutenberg 16+ * Extract the logic of checking the post template support for grid view toi separate function * Change the versions comparison and improve description of custom version compare function * Render Checkout/Cart containing pages without template overriding (#10359) * Render Checkout/Cart containing pages without template overriding * Fix checkout typo --------- Co-authored-by: Mike Jolley <[email protected]> * Add to cart form: Fix fatal error when missing `product` param in add_to_cart_redirect_filter (#10316) * Transform product param optional in add_to_cart_redirect_filter method * Remove unnecessary argument from add_to_cart_redirect_filter * Remove mocked filter call * Remove unnecessary argument from function docs * Remove opinionated styles from Product Hero pattern (#10255) * Mini Cart: Remove deprecated print_inline_script() (#10165) * Mini Cart: Replace the deprecated print_inline_script() with supported get_inline_script_data(). Fixes #10004 * Mini Cart: Add version check for the new get_inline_script_data() function * Update the variable names and fix a typo * Mini Cart: Add regex to check for the WP version * Abstract the WP version comparison regex to a separate Utils class * Call wc_setup_product_data if the global product variable is not an instance of WC_Product. (#10128) * Empty commit for release pull request * add testing instructions * Per block stylesheets (#9831) * Clean up blank lines * Update Webpack config * Update PHP logic to load block styles * Style fixes * Style fixes (II) * Style fixes (III) * Style fixes (IV) * Fix missing stylesheets in the Site Editor * Fix wrong return values in some PHP method docs * Fix missing ProductPrice stylesheet causing 404 in tests * Fix missing ProductGallery stylesheet causing 404 in tests * update testing instructions * add zip link * update version * update zip link * remove screenshot * remove testing instructions * Register Legacy block for all taxonomy-product_ template (#10382) * WIP * improve logic * improve unit test * $post validation on Cart and Checkout template (#10410) Co-authored-by: Luigi Teschio <[email protected]> * Update zip --------- Co-authored-by: Patricia Hillebrandt <[email protected]> Co-authored-by: Mike Jolley <[email protected]> Co-authored-by: Karol Manijak <[email protected]> Co-authored-by: Paulo Arromba <[email protected]> Co-authored-by: Alexandre Lara <[email protected]> Co-authored-by: Albert Juhé Lluveras <[email protected]> Co-authored-by: Daniel Dudzic <[email protected]> Co-authored-by: github-actions <[email protected]> Co-authored-by: Luigi <[email protected]>
This PR resolves the styling issues reporting in #10357, and the template migration issue reported in #10181. Both are related to how content is migrated, and how content renders after migration.
@wavvves @ralucaStan
Issue causes
wpautop
which introduces unwanted<br>
and<p>
tags around and within the rendered shortcode content. This is a know WP 6.2 issue (see trac links below).Refs:
wpautop
issue, with some workarounds. The fix I employed is similar but more specific so as not to affect other shortcodes.Fixes #10357
Fixes #10181
Testing
User Facing Testing
To setup your environment for testing:
[woocommerce_cart]
has_migrated_cart
andhas_migrated_checkout
. If you're using Local WP, you can use the Adminer tool it provides to access your DB.Testing steps:
<br>
tag.WooCommerce Visibility
Changelog
Not needed as this feature has not landed yet.