ages and * return it, there is no need to dig further. * 3. If the templates *are* in use, check if the `page-content-wrapper` block is in use. If so, get the content * from the pages (same as step 2) and return it. * 4. If the templates are in use but `page-content-wrapper` is not, then get the content directly from the * template and return it. * 5. At the end of each step, assign the found content to the relevant class properties and save them in a * transient with a 1-day lifespan. This will prevent us from having to do this work on every page load. */ $cart_checkout_content_cache_transient_name = 'jetpack_woocommerce_analytics_cart_checkout_content_sources'; $transient_value = get_transient( $cart_checkout_content_cache_transient_name ); if ( false !== $transient_value && ! empty( $transient_value['checkout_content_source'] ) && ! empty( $transient_value['cart_content_source'] ) ) { $this->cart_content_source = $transient_value['cart_content_source']; $this->checkout_content_source = $transient_value['checkout_content_source']; return; } $this->cart_checkout_templates_in_use = wp_is_block_theme() && class_exists( '\Automattic\WooCommerce\Blocks\Package' ) && version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '10.6.0', '>=' ); // Cart/Checkout *pages* are in use if the templates are not in use. Return their content and do nothing else. if ( ! $this->cart_checkout_templates_in_use ) { $cart_page = get_post( wc_get_page_id( 'cart' ) ); $checkout_page = get_post( wc_get_page_id( 'checkout' ) ); if ( $cart_page && isset( $cart_page->post_content ) ) { $this->cart_content_source = $cart_page->post_content; } if ( $checkout_page && isset( $checkout_page->post_content ) ) { $this->checkout_content_source = $checkout_page->post_content; } set_transient( $cart_checkout_content_cache_transient_name, array( 'cart_content_source' => $this->cart_content_source, 'checkout_content_source' => $this->checkout_content_source, ), DAY_IN_SECONDS ); return; } // We are in a Block theme - so we need to find out if the templates are being used. if ( function_exists( 'get_block_template' ) ) { $checkout_template = get_block_template( 'woocommerce/woocommerce//page-checkout' ); $cart_template = get_block_template( 'woocommerce/woocommerce//page-cart' ); if ( ! $checkout_template ) { $checkout_template = get_block_template( 'woocommerce/woocommerce//checkout' ); } if ( ! $cart_template ) { $cart_template = get_block_template( 'woocommerce/woocommerce//cart' ); } } if ( function_exists( 'gutenberg_get_block_template' ) ) { $checkout_template = gutenberg_get_block_template( 'woocommerce/woocommerce//page-checkout' ); $cart_template = gutenberg_get_block_template( 'woocommerce/woocommerce//page-cart' ); if ( ! $checkout_template ) { $checkout_template = gutenberg_get_block_template( 'woocommerce/woocommerce//checkout' ); } if ( ! $cart_template ) { $cart_template = gutenberg_get_block_template( 'woocommerce/woocommerce//cart' ); } } if ( ! empty( $checkout_template->content ) ) { // Checkout template is in use, but we need to see if the page-content-wrapper is in use, or if the template is being used directly. $this->checkout_content_source = $checkout_template->content; $is_using_page_content = str_contains( $checkout_template->content, '