get_product_id() ); } else { $product = $item['data']; } if ( ! $product || ! $product instanceof WC_Product ) { continue; } $data = $this->get_product_details( $product ); if ( $item instanceof WC_Order_Item_Product ) { $data['pq'] = $item->get_quantity(); } else { $data['pq'] = $item['quantity']; } $products[] = $data; } return wp_json_encode( $products ); } /** * Get Cart/Checkout page view shared data * * @deprecated 13.3 */ protected function get_cart_checkout_shared_data() { $cart = WC()->cart; $guest_checkout = ucfirst( get_option( 'woocommerce_enable_guest_checkout', 'No' ) ); $create_account = ucfirst( get_option( 'woocommerce_enable_signup_and_login_from_checkout', 'No' ) ); $coupons = $cart->get_coupons(); $coupon_used = 0; if ( is_countable( $coupons ) ) { $coupon_used = count( $coupons ) ? 1 : 0; } $enabled_payment_options = array_filter( WC()->payment_gateways->get_available_payment_gateways(), function ( $payment_gateway ) { if ( ! $payment_gateway instanceof WC_Payment_Gateway ) { return false; } return $payment_gateway->is_available(); } ); $enabled_payment_options = array_keys( $enabled_payment_options ); $cart_total = wc_prices_include_tax() ? $cart->get_cart_contents_total() + $cart->get_cart_contents_tax() : $cart->get_cart_contents_total(); $shared_data = array( 'products' => $this->format_items_to_json( $cart->get_cart() ), 'create_account' => $create_account, 'guest_checkout' => $guest_checkout, 'express_checkout' => 'null', // TODO: not solved yet. 'products_count' => $cart->get_cart_contents_count(), 'order_value' => $cart_total, 'shipping_options_count' => 'null', // TODO: not solved yet. 'coupon_used' => $coupon_used, 'payment_options' => $enabled_payment_options, ); return $shared_data; } /** * Gets the content of the cart/checkout page or where the cart/checkout page is ultimately derived from if using a template. * This method sets the class properties $checkout_content_source and $cart_content_source. * * @deprecated 13.3 * * @return void Does not return, but sets class properties. */ public function find_cart_checkout_content_sources() { /** * The steps we take to find the content are: * 1. Check the transient, if that contains content and is not expired, return that. * 2. Check if the cart/checkout templates are in use. If *not in use*, get the content from the pages 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 ( ! 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, '