WC_Settings_Emails::email_font_family
Creates the email font family field with custom font family applied to each option.
Method of the class: WC_Settings_Emails{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Settings_Emails = new WC_Settings_Emails(); $WC_Settings_Emails->email_font_family( $value );
- $value(array) (required)
- Field value array.
WC_Settings_Emails::email_font_family() WC Settings Emails::email font family code WC 10.6.2
<?php
public function email_font_family( $value ) {
$option_value = $value['value'];
// This is a temporary fix to prevent using custom fonts without fallback.
$custom_fonts = null;
?>
<tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
</th>
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
<script type="text/javascript">
function renderWithFont( node ) {
if ( ! node.element || ! node.element.value ) return node.text;
var $wrapper = jQuery( '<span></span>' );
$wrapper.css( {'font-family': node.element.dataset['font-family'] || node.element.value} );
$wrapper.text( node.text );
return $wrapper;
}
function fontsSelect( selector ) {
jQuery( selector ).selectWoo( {
minimumResultsForSearch: Infinity,
templateResult: renderWithFont
} );
}
jQuery( document.body )
.on( 'wc-enhanced-select-init', function() {
fontsSelect( '#<?php echo esc_js( $value['id'] ); ?>' );
} );
</script>
<select
name="<?php echo esc_attr( $value['field_name'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
>
<optgroup label="<?php echo esc_attr__( 'Standard fonts', 'woocommerce' ); ?>">
<?php
foreach ( EmailFont::$font as $key => $font_family ) {
?>
<option
value="<?php echo esc_attr( $key ); ?>"
data-font-family="<?php echo esc_attr( $font_family ); ?>"
<?php selected( $option_value, (string) $key ); ?>
><?php echo esc_html( $key ); ?></option>
<?php
}
?>
</optgroup>
<?php if ( $custom_fonts ) : ?>
<optgroup label="<?php echo esc_attr__( 'Custom fonts', 'woocommerce' ); ?>">
<?php
foreach ( $custom_fonts as $key => $val ) {
?>
<option
value="<?php echo esc_attr( $key ); ?>"
<?php selected( $option_value, (string) $key ); ?>
><?php echo esc_html( $val ); ?></option>
<?php
}
?>
</optgroup>
<?php endif; ?>
</select>
</td>
</tr>
<?php
}