ocks::max_rows', 6 ), 'default_rows' => wc_get_theme_support( 'product_blocks::default_rows', 3 ), 'thumbnail_size' => wc_get_theme_support( 'thumbnail_image_width', 300 ), 'placeholderImgSrc' => wc_placeholder_img_src(), 'min_height' => wc_get_theme_support( 'featured_block::min_height', 500 ), 'default_height' => wc_get_theme_support( 'featured_block::default_height', 500 ), 'isLargeCatalog' => $product_counts->publish > 100, 'limitTags' => $tag_count > 100, 'hasTags' => $tag_count > 0, 'taxesEnabled' => wc_tax_enabled(), 'couponsEnabled' => wc_coupons_enabled(), 'shippingEnabled' => wc_shipping_enabled(), 'displayItemizedTaxes' => 'itemized' === get_option( 'woocommerce_tax_total_display' ), 'displayShopPricesIncludingTax' => 'incl' === get_option( 'woocommerce_tax_display_shop' ), 'displayCartPricesIncludingTax' => 'incl' === get_option( 'woocommerce_tax_display_cart' ), 'checkoutShowLoginReminder' => 'yes' === get_option( 'woocommerce_enable_checkout_login_reminder' ), 'showAvatars' => '1' === get_option( 'show_avatars' ), 'reviewRatingsEnabled' => wc_review_ratings_enabled(), 'productCount' => array_sum( (array) $product_counts ), 'attributes' => array_values( wc_get_attribute_taxonomies() ), 'isShippingCalculatorEnabled' => filter_var( get_option( 'woocommerce_enable_shipping_calc' ), FILTER_VALIDATE_BOOLEAN ), 'wcBlocksAssetUrl' => plugins_url( 'assets/', __DIR__ ), 'wcBlocksBuildUrl' => plugins_url( 'build/', __DIR__ ), 'restApiRoutes' => [ '/wc/store' => array_keys( Package::container()->get( RestApi::class )->get_routes_from_namespace( 'wc/store' ) ), ], 'homeUrl' => esc_url( home_url( '/' ) ), 'storePages' => [ 'shop' => self::format_page_resource( $page_ids['shop'] ), 'cart' => self::format_page_resource( $page_ids['cart'] ), 'checkout' => self::format_page_resource( $page_ids['checkout'] ), 'privacy' => self::format_page_resource( $page_ids['privacy'] ), 'terms' => self::format_page_resource( $page_ids['terms'] ), ], 'checkoutAllowsGuest' => $checkout instanceof \WC_Checkout && false === filter_var( $checkout->is_registration_required(), FILTER_VALIDATE_BOOLEAN ), 'checkoutAllowsSignup' => $checkout instanceof \WC_Checkout && filter_var( $checkout->is_registration_enabled(), FILTER_VALIDATE_BOOLEAN ), 'baseLocation' => wc_get_base_location(), 'woocommerceBlocksPhase' => Package::feature()->get_flag(), 'hasDarkEditorStyleSupport' => current_theme_supports( 'dark-editor-style' ), 'loginUrl' => wp_login_url(), /* * translators: If your word count is based on single characters (e.g. East Asian characters), * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. * Do not translate into your own language. */ 'wordCountType' => _x( 'words', 'Word count type. Do not translate!', 'woocommerce' ), ] ); } /** * Format a page object into a standard array of data. * * @param WP_Post|int $page Page object or ID. * @return array */ protected static function format_page_resource( $page ) { if ( is_numeric( $page ) && $page > 0 ) { $page = get_post( $page ); } if ( ! is_a( $page, '\WP_Post' ) ) { return [ 'id' => 0, 'title' => '', 'permalink' => false, ]; } return [ 'id' => $page->ID, 'title' => $page->post_title, 'permalink' => get_permalink( $page->ID ), ]; } /** * Get the file modified time as a cache buster if we're in dev mode. * * @param string $file Local path to the file. * @return string The cache buster value to use for the given file. */ protected static function get_file_version( $file ) { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( \Automattic\WooCommerce\Blocks\Package::get_path() . $file ) ) { return filemtime( \Automattic\WooCommerce\Blocks\Package::get_path() . $file ); } return \Automattic\WooCommerce\Blocks\Package::get_version(); } /** * Queues a block script in the frontend. * * @since 2.3.0 * @since 2.6.0 Changed $name to $script_name and added $handle argument. * @since 2.9.0 Made it so scripts are not loaded in admin pages. * * @param string $script_name Name of the script used to identify the file inside build folder. * @param string $handle Optional. Provided if the handle should be different than the script name. `wc-` prefix automatically added. * @param array $dependencies Optional. An array of registered script handles this script depends on. Default empty array. */ public static function register_block_script( $script_name, $handle = '', $dependencies = [] ) { $asset_api = Package::container()->get( AssetApi::class ); $asset_api->register_block_script( $script_name, $handle, $dependencies ); } /** * Registers a style according to `wp_register_style`. * * @since 2.0.0 * * @param string $handle Name of the stylesheet. Should be unique. * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. * @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'. Accepts media types like * 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'. */ protected static function register_style( $handle, $src, $deps = [], $media = 'all' ) { $filename = str_replace( plugins_url( '/', __DIR__ ), '', $src ); $ver = self::get_file_version( $filename ); wp_register_style( $handle, $src, $deps, $ver, $media ); } }