plugin_url() . '/assets/css/blocks/editor.css', array( 'wp-edit-blocks' ) ); self::register_style( 'wc-block-style', WC()->plugin_url() . '/assets/css/blocks/style.css', array() ); // Shared libraries and components across all blocks. self::register_script( 'wc-vendors', WC()->plugin_url() . '/assets/js/blocks/vendors.js', array(), false ); $block_dependencies = array( 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-editor', 'wp-i18n', 'wp-url', 'lodash', 'wc-vendors', ); self::register_script( 'wc-handpicked-products', WC()->plugin_url() . '/assets/js/blocks/handpicked-products.js', $block_dependencies ); self::register_script( 'wc-product-best-sellers', WC()->plugin_url() . '/assets/js/blocks/product-best-sellers.js', $block_dependencies ); self::register_script( 'wc-product-category', WC()->plugin_url() . '/assets/js/blocks/product-category.js', $block_dependencies ); self::register_script( 'wc-product-new', WC()->plugin_url() . '/assets/js/blocks/product-new.js', $block_dependencies ); self::register_script( 'wc-product-on-sale', WC()->plugin_url() . '/assets/js/blocks/product-on-sale.js', $block_dependencies ); self::register_script( 'wc-product-top-rated', WC()->plugin_url() . '/assets/js/blocks/product-top-rated.js', $block_dependencies ); self::register_script( 'wc-products-attribute', WC()->plugin_url() . '/assets/js/blocks/products-attribute.js', $block_dependencies ); self::register_script( 'wc-featured-product', WC()->plugin_url() . '/assets/js/blocks/featured-product.js', $block_dependencies ); } /** * Register blocks, hooking up assets and render functions as needed. * * @since 2.0.0 */ public static function register_blocks() { require_once dirname( __FILE__ ) . '/class-wc-block-featured-product.php'; register_block_type( 'woocommerce/handpicked-products', array( 'editor_script' => 'wc-handpicked-products', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); register_block_type( 'woocommerce/product-best-sellers', array( 'editor_script' => 'wc-product-best-sellers', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); register_block_type( 'woocommerce/product-category', array( 'editor_script' => 'wc-product-category', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); register_block_type( 'woocommerce/product-new', array( 'editor_script' => 'wc-product-new', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); register_block_type( 'woocommerce/product-on-sale', array( 'editor_script' => 'wc-product-on-sale', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); register_block_type( 'woocommerce/product-top-rated', array( 'editor_script' => 'wc-product-top-rated', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); register_block_type( 'woocommerce/products-by-attribute', array( 'editor_script' => 'wc-products-attribute', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); register_block_type( 'woocommerce/featured-product', array( 'render_callback' => array( 'WC_Block_Featured_Product', 'render' ), 'editor_script' => 'wc-featured-product', 'editor_style' => 'wc-block-editor', 'style' => 'wc-block-style', ) ); } /** * Adds a WooCommerce category to the block inserter. * * @since 2.0.0 * * @param array $categories Array of categories. * @return array Array of block categories. */ public static function add_block_category( $categories ) { return array_merge( $categories, array( array( 'slug' => 'woocommerce', 'title' => __( 'WooCommerce', 'woocommerce' ), 'icon' => 'woocommerce', ), ) ); } /** * Output useful globals before printing any script tags. * * These are used by @woocommerce/components & the block library to set up defaults * based on user-controlled settings from WordPress. * * @since 2.0.0 */ public static function print_script_settings() { global $wp_locale; $code = get_woocommerce_currency(); // NOTE: wcSettings is not used directly, it's only for @woocommerce/components // // Settings and variables can be passed here for access in the app. // Will need `wcAdminAssetUrl` if the ImageAsset component is used. // Will need `dataEndpoints.countries` if Search component is used with 'country' type. // Will need `orderStatuses` if the OrderStatus component is used. // Deliberately excluding: `embedBreadcrumbs`, `trackingEnabled`. $settings = array( 'adminUrl' => admin_url(), 'wcAssetUrl' => plugins_url( 'assets/', WC_PLUGIN_FILE ), 'siteLocale' => esc_attr( get_bloginfo( 'language' ) ), 'currency' => array( 'code' => $code, 'precision' => wc_get_price_decimals(), 'symbol' => get_woocommerce_currency_symbol( $code ), 'position' => get_option( 'woocommerce_currency_pos' ), ), 'stockStatuses' => wc_get_product_stock_status_options(), 'siteTitle' => get_bloginfo( 'name' ), 'dataEndpoints' => array(), 'l10n' => array( 'userLocale' => get_user_locale(), 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ), ), ); // NOTE: wcSettings is not used directly, it's only for @woocommerce/components. $settings = apply_filters( 'woocommerce_components_settings', $settings ); // Global settings used in each block. $block_settings = array( 'min_columns' => wc_get_theme_support( 'product_grid::min_columns', 1 ), 'max_columns' => wc_get_theme_support( 'product_grid::max_columns', 6 ), 'default_columns' => wc_get_default_products_per_row(), 'min_rows' => wc_get_theme_support( 'product_grid::min_rows', 1 ), 'max_rows' => wc_get_theme_support( 'product_grid::max_rows', 6 ), 'default_rows' => wc_get_default_product_rows_per_page(), '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 ), ); ?>