appended. if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) { return; } if ( count( $script->deps ) ) { foreach ( $script->deps as $dep ) { if ( ! array_key_exists( $dep, $this->scripts_to_lazy_load ) ) { $dep_script = $this->get_script_from_handle( $dep ); if ( ! is_null( $dep_script ) ) { $this->append_script_and_deps_src( $dep_script ); } } } } if ( ! $script->src ) { return; } $this->scripts_to_lazy_load[ $script->handle ] = array( 'src' => $script->src, 'version' => $script->ver, 'before' => $wp_scripts->print_inline_script( $script->handle, 'before', false ), 'after' => $wp_scripts->print_inline_script( $script->handle, 'after', false ), 'translations' => $wp_scripts->print_translations( $script->handle, false ), ); } /** * Returns the markup for render the tax label. * * @return string */ protected function get_include_tax_label_markup() { $cart_controller = $this->get_cart_controller(); $cart = $cart_controller->get_cart_instance(); $cart_contents_total = $cart->get_subtotal(); return ( ! empty( $this->tax_label ) && 0 !== $cart_contents_total ) ? ( "" . esc_html( $this->tax_label ) . '' ) : ''; } /** * Append frontend scripts when rendering the Mini Cart block. * * @param array $attributes Block attributes. * @param string $content Block content. * * @return string Rendered block type output. */ protected function render( $attributes, $content ) { return $content . $this->get_markup( $attributes ); } /** * Render the markup for the Mini Cart block. * * @param array $attributes Block attributes. * * @return string The HTML markup. */ protected function get_markup( $attributes ) { if ( is_admin() || WC()->is_rest_api_request() ) { // In the editor we will display the placeholder, so no need to load // real cart data and to print the markup. return ''; } $cart_controller = $this->get_cart_controller(); $cart = $cart_controller->get_cart_instance(); $cart_contents_count = $cart->get_cart_contents_count(); $cart_contents = $cart->get_cart(); $cart_contents_total = $cart->get_subtotal(); if ( $cart->display_prices_including_tax() ) { $cart_contents_total += $cart->get_subtotal_tax(); } $classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color' ) ); $wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] ); $wrapper_styles = $classes_styles['styles']; $aria_label = sprintf( /* translators: %1$d is the number of products in the cart. %2$s is the cart total */ _n( '%1$d item in cart, total price of %2$s', '%1$d items in cart, total price of %2$s', $cart_contents_count, 'woocommerce' ), $cart_contents_count, wp_strip_all_tags( wc_price( $cart_contents_total ) ) ); $icon = ''; $button_html = '' . esc_html( wp_strip_all_tags( wc_price( $cart_contents_total ) ) ) . ' ' . $this->get_include_tax_label_markup() . ' ' . $icon . ' ' . $cart_contents_count . ' '; if ( is_cart() || is_checkout() ) { // It is not necessary to load the Mini Cart Block on Cart and Checkout page. return '
'; } $template_part_contents = ''; // Determine if we need to load the template part from the theme, or WooCommerce in that order. $theme_has_mini_cart = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ); $template_slug_to_load = $theme_has_mini_cart ? get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; $template_part = BlockTemplateUtils::get_block_template( $template_slug_to_load . '//mini-cart', 'wp_template_part' ); if ( $template_part && ! empty( $template_part->content ) ) { $template_part_contents = do_blocks( $template_part->content ); } if ( '' === $template_part_contents ) { $template_part_contents = do_blocks( // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents file_get_contents( Package::get_path() . 'templates/' . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'] . '/mini-cart.html' ) ); } return '' . __( 'Your cart is currently empty!', 'woocommerce' ) . '
', ) ); } }