*/ public static function get_connected_fields(): array { return array( 'gs_theme-settings' => array( 'shop_columns', 'shop_per_page', 'show_shop_sidebar', 'font_pairing', 'free_shipping_threshold', 'primary_color', 'secondary_color', 'tertiary_color', 'surface_color', 'on_surface_color', 'accent_color', ), 'gs_product-settings' => array( 'atc_label', ), ); } public static function init(): void { // shop_columns — WC product archive column count $cols = (int) slbuild_global_setting( 'theme-settings', 'shop_columns', 0 ); if ( $cols > 0 ) { add_filter( 'loop_shop_columns', static function() use ( $cols ) { return $cols; } ); } // shop_per_page — products per archive page $per_page = (int) slbuild_global_setting( 'theme-settings', 'shop_per_page', 0 ); if ( $per_page > 0 ) { add_filter( 'loop_shop_per_page', static function() use ( $per_page ) { return $per_page; } ); } // show_shop_sidebar — add body class so CSS can toggle sidebar $sidebar = slbuild_global_setting( 'theme-settings', 'show_shop_sidebar', '' ); if ( '' !== $sidebar ) { $has_sidebar = (bool) $sidebar; add_filter( 'body_class', static function( $classes ) use ( $has_sidebar ) { $classes[] = $has_sidebar ? 'slb-shop-sidebar' : 'slb-shop-no-sidebar'; return $classes; } ); } // font_pairing — enqueue Google Fonts if a pairing is chosen $font = slbuild_global_setting( 'theme-settings', 'font_pairing', '' ); if ( '' !== $font && 'default' !== $font ) { add_action( 'wp_enqueue_scripts', static function() use ( $font ) { self::enqueue_font( $font ); }, 5 ); } // atc_label — WooCommerce add-to-cart text on product loop $atc = slbuild_global_setting( 'product-settings', 'atc_label', '' ); if ( '' !== $atc ) { add_filter( 'woocommerce_product_add_to_cart_text', static function() use ( $atc ) { return esc_html( $atc ); } ); add_filter( 'woocommerce_product_single_add_to_cart_text', static function() use ( $atc ) { return esc_html( $atc ); } ); } // free_shipping_threshold — pass to JS for mini-cart progress bar $threshold = slbuild_global_setting( 'theme-settings', 'free_shipping_threshold', '' ); if ( '' !== $threshold ) { $threshold_int = (int) $threshold; add_action( 'wp_enqueue_scripts', static function() use ( $threshold_int ) { wp_register_script( 'slbuild-data', false, array(), false, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters wp_enqueue_script( 'slbuild-data' ); wp_add_inline_script( 'slbuild-data', 'window.slbuildFreeShipping=' . $threshold_int . ';' ); }, 5 ); } } /** * Enqueue a Google Fonts URL for a named pairing. * * @param string $pairing Pairing slug matching gs_theme-settings font_pairing options. */ private static function enqueue_font( string $pairing ): void { $map = array( 'inter' => 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap', 'playfair' => 'https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=Source+Sans+3:wght@400;600&display=swap', 'dm_sans' => 'https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap', 'nunito' => 'https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap', 'lora' => 'https://fonts.googleapis.com/css2?family=Lora:wght@400;600&family=Open+Sans:wght@400;600&display=swap', 'montserrat' => 'https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700&display=swap', ); $url = $map[ $pairing ] ?? ''; if ( $url ) { wp_enqueue_style( 'slbuild-font-' . esc_attr( $pairing ), $url, array(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion } } }