icting_styles() { if ( ! PageController::is_admin_or_embed_page() ) { return; } // Dequeing this to avoid conflicts, until we remove the 'woocommerce-page' class. wp_dequeue_style( 'woocommerce-blocktheme' ); } /** * Update the edit product links when the new experience is enabled. * * @param string $link The edit link. * @param int $post_id Post ID. * @return string */ public function update_edit_product_link( $link, $post_id ) { $product = wc_get_product( $post_id ); if ( ! $product ) { return $link; } if ( $product->get_type() === 'simple' ) { return admin_url( 'admin.php?page=wc-admin&path=/product/' . $product->get_id() ); } return $link; } /** * Enables variation post type in REST API. * * @param array $args Array of post type arguments. * @return array Array of post type arguments. */ public function enable_rest_api_for_product_variation( $args ) { $args['show_in_rest'] = true; return $args; } /** * Adds fields so that we can store user preferences for the variations block. * * @param array $user_data_fields User data fields. * @return array */ public function add_user_data_fields( $user_data_fields ) { return array_merge( $user_data_fields, array( 'variable_product_block_tour_shown', 'local_attributes_notice_dismissed_ids', 'variable_items_without_price_notice_dismissed', ) ); } /** * Sets the current screen to the block editor if a wc-admin page. */ public function set_current_screen_to_block_editor_if_wc_admin() { $screen = get_current_screen(); // phpcs:ignore Squiz.PHP.CommentedOutCode.Found // (no idea why I need that phpcs:ignore above, but I'm tired trying to re-write this comment to get it to pass) // we can't check the 'path' query param because client-side routing is used within wc-admin, // so this action handler is only called on the initial page load from the server, which might // not be the product edit page (it mostly likely isn't). if ( PageController::is_admin_page() ) { $screen->is_block_editor( true ); wp_add_inline_script( 'wp-blocks', 'wp.blocks && wp.blocks.unstable__bootstrapServerSideBlockDefinitions && wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' ); } } /** * Get the product editor settings. */ private function get_product_editor_settings() { $editor_settings = array(); $template_registry = wc_get_container()->get( BlockTemplateRegistry::class ); $block_template_logger = BlockTemplateLogger::get_instance(); $block_template_logger->log_template_events_to_file( 'simple-product' ); $block_template_logger->log_template_events_to_file( 'product-variation' ); $editor_settings['templates'] = array( 'product' => $template_registry->get_registered( 'simple-product' )->get_formatted_template(), 'product_variation' => $template_registry->get_registered( 'product-variation' )->get_formatted_template(), ); $editor_settings['templateEvents'] = array( 'product' => $block_template_logger->get_formatted_template_events( 'simple-product' ), 'product_variation' => $block_template_logger->get_formatted_template_events( 'product-variation' ), ); $block_editor_context = new WP_Block_Editor_Context( array( 'name' => self::EDITOR_CONTEXT_NAME ) ); return get_block_editor_settings( $editor_settings, $block_editor_context ); } /** * Register product editor templates. */ private function register_product_editor_templates() { $template_registry = wc_get_container()->get( BlockTemplateRegistry::class ); $template_registry->register( new SimpleProductTemplate() ); $template_registry->register( new ProductVariationTemplate() ); } }