【问题标题】:Increase the displayed text size of a WooCommerce email custom field增加 WooCommerce 电子邮件自定义字段的显示文本大小
【发布时间】:2021-04-09 10:21:31
【问题描述】:

我想增加 HTML 电子邮件中自定义字段的文本大小。我该如何使用此代码?

add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $fields['name_460'] = array(
        'label' => __( 'Customer Notes' ),
        'value' => get_post_meta( $order->id, 'name_460', true ),
    );
    return $fields;
}

【问题讨论】:

  • “我想增加自定义字段的文本大小...”是什么意思?你的问题不清楚
  • 该自定义字段的文本大小非常小,人们难以阅读。所以我想放大它。

标签: php wordpress woocommerce custom-fields text-size


【解决方案1】:

要增加 WooCommerce 电子邮件通知中自定义字段值的文本大小,您可以改用以下内容:

add_filter( 'woocommerce_email_order_meta_fields', 'filter_wc_email_order_meta_fields', 10, 3 );
function filter_wc_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $size = 20; // Set here the text size in pixels (px)
    
    $fields['name_460'] = array(
        'label' => __( 'Customer Notes' ),
        'value' => '<span style="font-size:'.$size.'px;">' . $order->get_meta('name_460') . '</span>',
    );
    return $fields;
}

代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。


如果您还需要增加标签文本替换该行:

'label' => __( 'Customer Notes' ),

与:

'label' => '<span style="font-size:'.$size.'px;">' . __( 'Customer Notes' ) . '</span>',

您也可以使用以下方式,使用不同的钩子:

add_filter( 'woocommerce_email_order_meta', 'action_wc_email_order_meta', 20, 4 );
function action_wc_email_order_meta( $order, $sent_to_admin, $plain_text, $email ) {
    $size  = 20; // Set here the text size in pixels (px)
    $label = __('Customer Notes', 'woocommerce'); // Define the label text
    $value = $order->get_meta('name_460'); // Get custom field value
    
    echo '<p style="font-size:'.$size.'px;"><strong>' . $label . ':</strong> ' . $value . '</p>';
}

【讨论】:

    猜你喜欢
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2018-08-31
    • 2020-12-07
    • 2021-03-29
    • 2020-09-09
    • 2021-02-01
    相关资源
    最近更新 更多