{ return true; } return false; } /** * Check if the current theme is a block theme. * * @since 6.0.0 * @return bool */ function wc_current_theme_is_fse_theme() { if ( function_exists( 'wp_is_block_theme' ) ) { return (bool) wp_is_block_theme(); } if ( function_exists( 'gutenberg_is_fse_theme' ) ) { return (bool) gutenberg_is_fse_theme(); } return false; } /** * Check if the current theme has WooCommerce support or is a FSE theme. * * @since 6.0.0 * @return bool */ function wc_current_theme_supports_woocommerce_or_fse() { return (bool) current_theme_supports( 'woocommerce' ) || wc_current_theme_is_fse_theme(); } /** * Given an element name, returns a class name. * * If the WP-related function is not defined or current theme is not a FSE theme, return empty string. * * @param string $element The name of the element. * * @since 7.0.1 * @return string */ function wc_wp_theme_get_element_class_name( $element ) { if ( wc_current_theme_is_fse_theme() && function_exists( 'wp_theme_get_element_class_name' ) ) { return wp_theme_get_element_class_name( $element ); } return ''; } /** * Given an element name, returns true or false depending on whether the * current theme has styles for that element defined in theme.json. * * If the theme is not a block theme or the WP-related function is not defined, * return false. * * @param string $element The name of the element. * * @since 7.4.0 * @return bool */ function wc_block_theme_has_styles_for_element( $element ) { if ( ! wc_current_theme_is_fse_theme() || wc_wp_theme_get_element_class_name( $element ) === '' ) { return false; } if ( function_exists( 'wp_get_global_styles' ) ) { $global_styles = wp_get_global_styles(); if ( array_key_exists( 'elements', $global_styles ) && array_key_exists( $element, $global_styles['elements'] ) ) { return is_array( $global_styles['elements'][ $element ] ); } } return false; }