diff --git a/plugins/woocommerce/changelog/48300-add-type-of-cart-and-checkout-to-system-report b/plugins/woocommerce/changelog/48300-add-type-of-cart-and-checkout-to-system-report
new file mode 100644
index 00000000000..bcfe46bb4cc
--- /dev/null
+++ b/plugins/woocommerce/changelog/48300-add-type-of-cart-and-checkout-to-system-report
@@ -0,0 +1,4 @@
+Significance: minor
+Type: enhancement
+
+Add information about block/shortcode/template usage on Cart and Checkout pages to the WC system report.
diff --git a/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php b/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php
index 04c8d767399..7b998c85c64 100644
--- a/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php
+++ b/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php
@@ -6,6 +6,7 @@
*/
use Automattic\Jetpack\Constants;
+use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
use Automattic\WooCommerce\Utilities\RestApiUtil;
defined( 'ABSPATH' ) || exit;
@@ -873,10 +874,38 @@ if ( 0 < $mu_plugins_count ) :
echo ' ' . ( $_page['block_required'] ? sprintf( esc_html__( 'Page does not contain the %1$s shortcode or the %2$s block.', 'woocommerce' ), esc_html( $_page['shortcode'] ), esc_html( $_page['block'] ) ) : sprintf( esc_html__( 'Page does not contain the %s shortcode.', 'woocommerce' ), esc_html( $_page['shortcode'] ) ) ) . ''; /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */
$found_error = true;
}
+
+ // Warn merchants if both the shortcode and block are present, which will be a confusing shopper experience.
+ if ( $_page['shortcode_present'] && $_page['block_present'] ) {
+ /* Translators: %1$s: shortcode text, %2$s: block slug. */
+ echo ' ' . sprintf( esc_html__( 'Page contains both the %1$s shortcode and the %2$s block.', 'woocommerce' ), esc_html( $_page['shortcode'] ), esc_html( $_page['block'] ) ) . ''; /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */
+ $found_error = true;
+ }
}
if ( ! $found_error ) {
- echo '#' . absint( $_page['page_id'] ) . ' - ' . esc_html( str_replace( home_url(), '', get_permalink( $_page['page_id'] ) ) ) . '';
+
+ $additional_info = '';
+
+ // We only state the used type on the Checkout and the Cart page.
+ if ( in_array( $_page['block'], array( 'woocommerce/checkout', 'woocommerce/cart' ), true ) ) {
+ // We check first if, in a blocks theme, the template content does not load the page content.
+ if ( CartCheckoutUtils::is_overriden_by_custom_template_content( $_page['block'] ) ) {
+ $additional_info = __( "This page's content is overridden by custom template content", 'woocommerce' );
+ } elseif ( $_page['shortcode_present'] ) {
+ /* Translators: %1$s: shortcode text. */
+ $additional_info = sprintf( __( 'Contains the %1$s shortcode', 'woocommerce' ), esc_html( $_page['shortcode'] ) );
+ } elseif ( $_page['block_present'] ) {
+ /* Translators: %1$s: block slug. */
+ $additional_info = sprintf( __( 'Contains the %1$s block', 'woocommerce' ), esc_html( $_page['block'] ) );
+ }
+
+ if ( ! empty( $additional_info ) ) {
+ $additional_info = ' - ' . $additional_info . '';
+ }
+ }
+
+ echo '#' . absint( $_page['page_id'] ) . ' - ' . esc_html( str_replace( home_url(), '', get_permalink( $_page['page_id'] ) ) ) . '' . $additional_info; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
}
echo '';
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
index 32b01e3f296..4db1cb042ec 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
@@ -1407,36 +1407,39 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
$shortcode_required = false;
$block_present = false;
$block_required = false;
+ $page = false;
// Page checks.
if ( $page_id ) {
$page_set = true;
- }
- if ( get_post( $page_id ) ) {
- $page_exists = true;
- }
- if ( 'publish' === get_post_status( $page_id ) ) {
- $page_visible = true;
+ $page = get_post( $page_id );
+
+ if ( $page ) {
+ $page_exists = true;
+
+ if ( 'publish' === $page->post_status ) {
+ $page_visible = true;
+ }
+ }
}
// Shortcode checks.
- if ( $values['shortcode'] && get_post( $page_id ) ) {
+ if ( $values['shortcode'] && $page ) {
$shortcode_required = true;
- $page = get_post( $page_id );
- if ( strstr( $page->post_content, $values['shortcode'] ) ) {
+ if ( has_shortcode( $page->post_content, trim( $values['shortcode'], '[]' ) ) ) {
$shortcode_present = true;
}
+
+ // Compatibility with the classic shortcode block which can be used instead of shortcodes.
+ if ( ! $shortcode_present && ( 'woocommerce/checkout' === $values['block'] || 'woocommerce/cart' === $values['block'] ) ) {
+ $shortcode_present = has_block( 'woocommerce/classic-shortcode', $page->post_content );
+ }
}
// Block checks.
- if ( $values['block'] && get_post( $page_id ) ) {
+ if ( $values['block'] && $page ) {
$block_required = true;
- $block_present = WC_Blocks_Utils::has_block_in_page( $page_id, $values['block'] );
-
- // Compatibility with the classic shortcode block which can be used instead of shortcodes.
- if ( ! $block_present && ( 'woocommerce/checkout' === $values['block'] || 'woocommerce/cart' === $values['block'] ) ) {
- $block_present = WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/classic-shortcode', true );
- }
+ $block_present = has_block( $values['block'], $page->post_content );
}
// Wrap up our findings into an output array.
diff --git a/plugins/woocommerce/src/Blocks/Utils/CartCheckoutUtils.php b/plugins/woocommerce/src/Blocks/Utils/CartCheckoutUtils.php
index 37628fc7e59..53b4cde7f56 100644
--- a/plugins/woocommerce/src/Blocks/Utils/CartCheckoutUtils.php
+++ b/plugins/woocommerce/src/Blocks/Utils/CartCheckoutUtils.php
@@ -44,6 +44,32 @@ class CartCheckoutUtils {
return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id );
}
+
+ /**
+ * Checks if the template overriding the page loads the page content or not.
+ * Templates by default load the page content, but if that block is deleted the content can get out of sync with the one presented in the page editor.
+ *
+ * @param string $block The block to check.
+ *
+ * @return bool true if the template has out of sync content.
+ */
+ public static function is_overriden_by_custom_template_content( string $block ): bool {
+
+ $block = str_replace( 'woocommerce/', '', $block );
+
+ if ( wc_current_theme_is_fse_theme() ) {
+ $templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( 'page-' . $block ) );
+ foreach ( $templates_from_db as $template ) {
+ if ( ! has_block( 'woocommerce/page-content-wrapper', $template->content ) ) {
+ // Return true if the template does not load the page content via the woocommerce/page-content-wrapper block.
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
/**
* Gets country codes, names, states, and locale information.
*