Commit 2351461e17 for woocommerce
commit 2351461e1776bd012e898cb6a34c7b9963d18328
Author: Tom Cafferkey <tjcafferkey@gmail.com>
Date: Wed Sep 17 08:49:38 2025 +0100
Ensure child themes load parent fonts in coming soon mode. (#60845)
* Check if current theme is a child theme and if so load parent fonts
* Add changelog
* Fix linting
* Allow get_file_contents()
diff --git a/plugins/woocommerce/changelog/fix-coming-soon-child-themes-load-parent-fonts b/plugins/woocommerce/changelog/fix-coming-soon-child-themes-load-parent-fonts
new file mode 100644
index 0000000000..4e0043d705
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-coming-soon-child-themes-load-parent-fonts
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Ensure child themes load parent fonts in coming soon mode
diff --git a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php
index 66dbec4ef4..98d906c03b 100644
--- a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php
+++ b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php
@@ -183,9 +183,11 @@ class ComingSoonRequestHandler {
}
/**
- * Filters the theme.json data to add the Inter and Cardo fonts when they don't exist.
+ * Filters the theme.json data to add Coming Soon fonts.
+ * This runs after child theme merging to ensure parent theme fonts are included.
*
- * @param WP_Theme_JSON $theme_json The theme json object.
+ * @param WP_Theme_JSON_Data $theme_json The theme json data object.
+ * @return WP_Theme_JSON_Data The filtered theme json data.
*/
public function experimental_filter_theme_json_theme( $theme_json ) {
if ( ! Features::is_enabled( 'launch-your-store' ) ) {
@@ -195,6 +197,36 @@ class ComingSoonRequestHandler {
$theme_data = $theme_json->get_data();
$font_data = $theme_data['settings']['typography']['fontFamilies']['theme'] ?? array();
+ // Check if the current theme is a child theme. And if so, merge the parent theme fonts with the existing fonts.
+ if ( wp_get_theme()->parent() ) {
+ $parent_theme = wp_get_theme()->parent();
+ $parent_theme_json_file = $parent_theme->get_file_path( 'theme.json' );
+
+ if ( is_readable( $parent_theme_json_file ) ) {
+ $parent_theme_json_data = json_decode( file_get_contents( $parent_theme_json_file ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
+
+ if ( isset( $parent_theme_json_data['settings']['typography']['fontFamilies'] ) ) {
+ $parent_fonts = $parent_theme_json_data['settings']['typography']['fontFamilies'];
+
+ // Merge parent theme fonts with existing fonts.
+ foreach ( $parent_fonts as $parent_font ) {
+ $found = false;
+ foreach ( $font_data as $existing_font ) {
+ if ( isset( $parent_font['name'] ) && isset( $existing_font['name'] ) &&
+ $parent_font['name'] === $existing_font['name'] ) {
+ $found = true;
+ break;
+ }
+ }
+
+ if ( ! $found ) {
+ $font_data[] = $parent_font;
+ }
+ }
+ }
+ }
+ }
+
$fonts_to_add = array(
array(
'fontFamily' => '"Inter", sans-serif',
@@ -225,7 +257,7 @@ class ComingSoonRequestHandler {
),
);
- // Loops through all existing fonts and append when the font's name is not found.
+ // Add WooCommerce fonts if they don't already exist.
foreach ( $fonts_to_add as $font_to_add ) {
$found = false;
foreach ( $font_data as $font ) {