tom_css";s:15:"option_category";s:6:"layout";}s:13:"contact_title";a:4:{s:5:"label";s:13:"Kontakt-Titel";s:8:"selector";s:25:".et_pb_contact_main_title";s:11:"toggle_slug";s:10:"custom_css";s:15:"option_category";s:6:"layout";}s:14:"contact_button";a:5:{s:5:"label";s:14:"Kontakt-Button";s:8:"selector";s:93:".et_pb_contact_form_container .et_contact_bottom_container .et_pb_contact_submit.et_pb_button";s:24:"no_space_before_selector";b:1;s:11:"toggle_slug";s:10:"custom_css";s:15:"option_category";s:6:"layout";}s:14:"contact_fields";a:4:{s:5:"label";s:14:"Formularfelder";s:8:"selector";s:5:"input";s:11:"toggle_slug";s:10:"custom_css";s:15:"option_category";s:6:"layout";}s:10:"text_field";a:4:{s:5:"label";s:15:"Nachrichtenfeld";s:8:"selector";s:30:"textarea.et_pb_contact_message";s:11:"toggle_slug";s:10:"custom_css";s:15:"option_category";s:6:"layout";}s:13:"captcha_field";a:4:{s:5:"label";s:12:"Captcha-Feld";s:8:"selector";s:27:"input.et_pb_contact_captcha";s:11:"toggle_slug";s:10:"custom_css";s:15:"option_category";s:6:"layout";}s:13:"captcha_label";a:4:{s:5:"label";s:12:"Captcha-Text";s:8:"selector";s:22:".et_pb_contact_right p";s:11:"toggle_slug";s:10:"custom_css";s:15:"option_category";s:6:"layout";}}}s:19:"et_pb_contact_field";a:4:{s:15:"advanced_fields";a:19:{s:7:"borders";a:1:{s:7:"default";a:2:{s:3:"css";a:2:{s:4:"main";a:2:{s:12:"border_radii";s:271:".et_pb_contact_form_container %%order_class%%.et_pb_contact_field .input, .et_pb_contact_form_container %%order_class%%.et_pb_contact_field .input[type="checkbox"] + label i, .et_pb_contact_form_container %%order_class%%.et_pb_contact_field .input[type="radio"] + label i";s:13:"border_styles";s:271:".et_pb_contact_form_container %%order_class%%.et_pb_contact_field .input, .et_pb_contact_form_container %%order_class%%.et_pb_contact_field .input[type="checkbox"] + label i, .et_pb_contact_form_container %%order_class%%.et_pb_contact_field .input[type="radio"] + label i";}s:9:"important";s:11:"plugin_only";}s:12:"label_prefix";s:7:"Eingabe";}}s:10:"box_shadow";a:1:{s:7:"default";a:1:{s:3:"css";a:2:{s:4:"main";s:132:"%%order_class%% input, %%order_class%% select, %%order_class%% textarea, %%order_class%% .et_pb_contact_field_options_list label > i";s:9:"important";b:1;}}}s:10:"background";a:10:{s:27:"has_background_color_toggle";b:0;s:20:"use_background_color";b:1;s:29:"use_background_color_gradient";b:1;s:20:"use_background_image";b:1;s:29:"use_background_image_parallax";b:1;s:20:"use_background_video";b:1;s:26:"use_background_color_reset";b:1;s:22:"use_background_pattern";b:1;s:19:"use_background_mask";b:1;s:3:"css";a:1:{s:4:"main";s:15:"%%order_class%%";}}s:14:"margin_padding";a:5:{s:10:"use_margin";b:1;s:16:"draggable_margin";b:1;s:11:"use_padding";b:1;s:17:"draggable_padding";b:1;s:3:"css";a:2:{s:7:"padding";s:16:"p%%order_class%%";s:9:"important";a:1:{i:0;s:13:"custom_margin";}}}s:4:"text";a:1:{s:3:"css";a:1:{s:16:"text_orientation";s:70:"%%order_class%% input, %%order_class%% textarea, %%order_class%% label";}}s:11:"text_shadow";a:1:{s:7:"default";b:0;}s:7:"filters";a:1:{s:3:"css";a:1:{s:4:"main";a:3:{i:0;s:21:"%%order_class%% input";i:1;s:24:"%%order_class%% textarea";i:2;s:21:"%%order_class%% label";}}}s:6:"button";b:0;s:6:"sticky";b:0;s:10:"form_field";a:1:{s:10:"form_field";a:6:{s:5:"label";s:4:"Feld";s:3:"css";a:9:{s:16:"background_color";s:181:"%%order_class%%.et_pb_contact_field .input, %%order_class%%.et_pb_contact_field .input[type="checkbox"] + label i, %%order_class%%.et_pb_contact_field .input[type="radio"] + label i";s:4:"main";s:42:"%%order_class%%.et_pb_contact_field .input";s:22:"background_color_hover";s:200:"%%order_class%%.et_pb_contact_field .input:hover, %%order_class%%.et_pb_contact_field .input[type="checkbox"] + label:hover i, %%order_class%%.et_pb_contact_field .input[type="radio"] + label:hover i";s:22:"focus_background_color";s:201:"%%order_class%%.et_pb_contact_field .input:focus, %%order_class%%.et_pb_contact_field .input[type="checkbox"]:active + label i, %%order_class%%.et_pb_contact_field .input[type="radio"]:active + label i";s:28:"fabel, '' ); $cart_payload = $this->get_cart_payload(); $this->asset_data_registry->add( 'cartTotals', isset( $cart_payload['totals'] ) ? $cart_payload['totals'] : null, null ); $this->asset_data_registry->add( 'cartItemsCount', isset( $cart_payload['items_count'] ) ? $cart_payload['items_count'] : null, null ); } $this->asset_data_registry->add( 'displayCartPricesIncludingTax', $this->display_cart_prices_including_tax, true ); $template_part_edit_uri = ''; if ( current_user_can( 'edit_theme_options' ) && wc_current_theme_is_fse_theme() ) { $theme_slug = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; if ( version_compare( get_bloginfo( 'version' ), '5.9', '<' ) ) { $site_editor_uri = add_query_arg( array( 'page' => 'gutenberg-edit-site' ), admin_url( 'themes.php' ) ); } else { $site_editor_uri = add_query_arg( array( 'canvas' => 'edit', 'path' => '/template-parts/single', ), admin_url( 'site-editor.php' ) ); } $template_part_edit_uri = add_query_arg( array( 'postId' => sprintf( '%s//%s', $theme_slug, 'mini-cart' ), 'postType' => 'wp_template_part', ), $site_editor_uri ); } $this->asset_data_registry->add( 'templatePartEditUri', $template_part_edit_uri, '' ); /** * Fires after cart block data is registered. * * @since 5.8.0 */ do_action( 'woocommerce_blocks_cart_enqueue_data' ); } /** * Function to enqueue `wc-settings` script and dequeue it later on so when * AssetDataRegistry runs, it appears enqueued- This allows the necessary * data to be printed to the page. */ public function enqueue_wc_settings() { // Return early if another block has already enqueued `wc-settings`. if ( wp_script_is( 'wc-settings', 'enqueued' ) ) { return; } // We are lazy-loading `wc-settings`, but we need to enqueue it here so // AssetDataRegistry knows it's going to load. wp_enqueue_script( 'wc-settings' ); // After AssetDataRegistry function runs, we dequeue `wc-settings`. add_action( 'wp_print_footer_scripts', array( $this, 'dequeue_wc_settings' ), 4 ); } /** * Function to dequeue `wc-settings` script. */ public function dequeue_wc_settings() { wp_dequeue_script( 'wc-settings' ); } /** * Prints the variable containing information about the scripts to lazy load. */ public function print_lazy_load_scripts() { $script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' ); $num_dependencies = count( $script_data['dependencies'] ); $wp_scripts = wp_scripts(); for ( $i = 0; $i < $num_dependencies; $i++ ) { $dependency = $script_data['dependencies'][ $i ]; foreach ( $wp_scripts->registered as $script ) { if ( $script->handle === $dependency ) { $this->append_script_and_deps_src( $script ); break; } } } $payment_method_registry = Package::container()->get( PaymentMethodRegistry::class ); $payment_methods = $payment_method_registry->get_all_active_payment_method_script_dependencies(); foreach ( $payment_methods as $payment_method ) { $payment_method_script = $this->get_script_from_handle( $payment_method ); if ( ! is_null( $payment_method_script ) ) { $this->append_script_and_deps_src( $payment_method_script ); } } $this->scripts_to_lazy_load['wc-block-mini-cart-component-frontend'] = array( 'src' => $script_data['src'], 'version' => $script_data['version'], 'translations' => $this->get_inner_blocks_translations(), ); $inner_blocks_frontend_scripts = array(); $cart = $this->get_cart_instance(); if ( $cart ) { // Preload inner blocks frontend scripts. $inner_blocks_frontend_scripts = $cart->is_empty() ? array( 'empty-cart-frontend', 'filled-cart-frontend', 'shopping-button-frontend', ) : array( 'empty-cart-frontend', 'filled-cart-frontend', 'title-frontend', 'items-frontend', 'footer-frontend', 'products-table-frontend', 'cart-button-frontend', 'checkout-button-frontend', 'title-label-frontend', 'title-items-counter-frontend', ); } foreach ( $inner_blocks_frontend_scripts as $inner_block_frontend_script ) { $script_data = $this->asset_api->get_script_data( 'build/mini-cart-contents-block/' . $inner_block_frontend_script . '.js' ); $this->scripts_to_lazy_load[ 'wc-block-' . $inner_block_frontend_script ] = array( 'src' => $script_data['src'], 'version' => $script_data['version'], ); } $data = rawurlencode( wp_json_encode( $this->scripts_to_lazy_load ) ); $mini_cart_dependencies_script = "var wcBlocksMiniCartFrontendDependencies = JSON.parse( decodeURIComponent( '" . esc_js( $data ) . "' ) );"; wp_add_inline_script( 'wc-mini-cart-block-frontend', $mini_cart_dependencies_script, 'before' ); } /** * Returns the script data given its handle. * * @param string $handle Handle of the script. * * @return \_WP_Dependency|null Object containing the script data if found, or null. */ protected function get_script_from_handle( $handle ) { $wp_scripts = wp_scripts(); foreach ( $wp_scripts->registered as $script ) { if ( $script->handle === $handle ) { return $script; } } return null; } /** * Recursively appends a scripts and its dependencies into the scripts_to_lazy_load array. * * @param \_WP_Dependency $script Object containing script data. */ protected function append_script_and_deps_src( $script ) { $wp_scripts = wp_scripts(); // This script and its dependencies have already been appended. if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) || isset( $wp_scripts->queue[ $script->handle ] ) ) { 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; } $site_url = site_url() ?? wp_guess_url(); $this->scripts_to_lazy_load[ $script->handle ] = array( 'src' => preg_match( '|^(https?:)?//|', $script->src ) ? $script->src : $site_url . $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 the cart price. * * @param array $attributes Block attributes. * * @return string */ protected function get_cart_price_markup( $attributes ) { if ( isset( $attributes['hasHiddenPrice'] ) && false !== $attributes['hasHiddenPrice'] ) { return; } return '' . $this->get_include_tax_label_markup(); } /** * Returns the markup for render the tax label. * * @return string */ protected function get_include_tax_label_markup() { if ( empty( $this->tax_label ) ) { return ''; } return "'; } /** * Append frontend scripts when rendering the Mini-Cart block. * * @param array $attributes Block attributes. * @param string $content Block content. * @param WP_Block $block Block instance. * @return string Rendered block type output. */ protected function render( $attributes, $content, $block ) { 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 ''; } $classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color', 'font_size', 'font_weight', 'font_family' ) ); $wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] ); if ( ! empty( $attributes['className'] ) ) { $wrapper_classes .= ' ' . $attributes['className']; } $wrapper_styles = $classes_styles['styles']; $icon = ' '; $button_html = $this->get_cart_price_markup( $attributes ) . ' ' . $icon . ' '; if ( is_cart() || is_checkout() ) { if ( $this->should_not_render_mini_cart( $attributes ) ) { return ''; } // 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 DB, the theme or WooCommerce in that order. $templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( 'mini-cart' ), 'wp_template_part' ); if ( count( $templates_from_db ) > 0 ) { $template_slug_to_load = $templates_from_db[0]->theme; } else { $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 '
'; } /** * Return the main instance of WC_Cart class. * * @return \WC_Cart CartController class instance. */ protected function get_cart_instance() { $cart = WC()->cart; if ( $cart && $cart instanceof \WC_Cart ) { return $cart; } return null; } /** * Get array with data for handle the tax label. * the entire logic of this function is was taken from: * https://github.com/woocommerce/woocommerce/blob/e730f7463c25b50258e97bf56e31e9d7d3bc7ae7/includes/class-wc-cart.php#L1582 * * @return array; */ protected function get_tax_label() { $cart = $this->get_cart_instance(); if ( $cart && $cart->display_prices_including_tax() ) { if ( ! wc_prices_include_tax() ) { $tax_label = WC()->countries->inc_tax_or_vat(); $display_cart_prices_including_tax = true; return array( 'tax_label' => $tax_label, 'display_cart_prices_including_tax' => $display_cart_prices_including_tax, ); } return array( 'tax_label' => '', 'display_cart_prices_including_tax' => true, ); } if ( wc_prices_include_tax() ) { $tax_label = WC()->countries->ex_tax_or_vat(); return array( 'tax_label' => $tax_label, 'display_cart_prices_including_tax' => false, ); }; return array( 'tax_label' => '', 'display_cart_prices_including_tax' => false, ); } /** * Get Cart Payload. * * @return object; */ protected function get_cart_payload() { $notices = wc_get_notices(); // Backup the notices because StoreAPI will remove them. $payload = WC()->api->get_endpoint_data( '/wc/store/cart' ); if ( ! empty( $notices ) ) { wc_set_notices( $notices ); // Restore the notices. } return $payload; } /** * Prepare translations for inner blocks and dependencies. */ protected function get_inner_blocks_translations() { $wp_scripts = wp_scripts(); $translations = array(); $chunks = $this->get_chunks_paths( $this->chunks_folder ); $vendor_chunks = $this->get_chunks_paths( 'vendors--mini-cart-contents-block' ); $shared_chunks = [ 'cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend' ]; foreach ( array_merge( $chunks, $vendor_chunks, $shared_chunks ) as $chunk ) { $handle = 'wc-blocks-' . $chunk . '-chunk'; $this->asset_api->register_script( $handle, $this->asset_api->get_block_asset_build_path( $chunk ), [], true ); $translations[] = $wp_scripts->print_translations( $handle, false ); wp_deregister_script( $handle ); } $translations = array_filter( $translations ); return implode( '', $translations ); } /** * Register block pattern for Empty Cart Message to make it translatable. */ public function register_empty_cart_message_block_pattern() { register_block_pattern( 'woocommerce/mini-cart-empty-cart-message', array( 'title' => __( 'Empty Mini-Cart Message', 'woocommerce' ), 'inserter' => false, 'content' => '

' . __( 'Your cart is currently empty!', 'woocommerce' ) . '

', ) ); } /** * Returns whether the Mini-Cart should be rendered or not. * * @param array $attributes Block attributes. * * @return bool */ public function should_not_render_mini_cart( array $attributes ) { return isset( $attributes['cartAndCheckoutRenderStyle'] ) && 'hidden' !== $attributes['cartAndCheckoutRenderStyle']; } }