@@ -37,6 +37,7 @@ protected function init() {
3737 add_action ( 'init ' , array ( $ this , 'register_assets ' ) );
3838 add_action ( 'body_class ' , array ( $ this , 'add_theme_body_class ' ), 1 );
3939 add_action ( 'admin_body_class ' , array ( $ this , 'add_theme_body_class ' ), 1 );
40+ add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'update_block_style_dependencies ' ), 20 );
4041 }
4142
4243 /**
@@ -120,4 +121,27 @@ protected function register_style( $handle, $src, $deps = [], $media = 'all' ) {
120121 $ ver = self ::get_file_version ( $ filename );
121122 wp_register_style ( $ handle , $ src , $ deps , $ ver , $ media );
122123 }
124+
125+ /**
126+ * Update block style dependencies after they have been registered.
127+ */
128+ public function update_block_style_dependencies () {
129+ $ wp_styles = wp_styles ();
130+ $ style = $ wp_styles ->query ( 'wc-blocks-style ' , 'registered ' );
131+
132+ if ( ! $ style ) {
133+ return ;
134+ }
135+
136+ // In WC < 5.5, `woocommerce-general` is not registered in block editor
137+ // screens, so we don't add it as a dependency if it's not registered.
138+ // In WC >= 5.5, `woocommerce-general` is registered on `admin_enqueue_scripts`,
139+ // so we need to check if it's registered here instead of on `init`.
140+ if (
141+ wp_style_is ( 'woocommerce-general ' , 'registered ' ) &&
142+ ! in_array ( 'woocommerce-general ' , $ style ->deps , true )
143+ ) {
144+ $ style ->deps [] = 'woocommerce-general ' ;
145+ }
146+ }
123147}
0 commit comments