php - Woocommerce - 从错误消息中删除 'Billing' 字

标签 php wordpress woocommerce

在结帐错误中使用 Woocommerce 2.6.4 时,即使标签文本已设置,所需的字段名称也会自动在错误消息中获得“Billing”作为前缀。

Ex. "Billing First Name is required"

错误是从这里产生的:

<ul class="woocommerce-error">
   <?php foreach ( $messages as $message ) : ?>
        <li><?php echo wp_kses_post( $message ); ?></li>
   <?php endforeach; ?>
</ul>

在 functions.php 中,标签名称是这样设置的:

add_filter( 'woocommerce_checkout_fields' , 'custom_wc_checkout_fields' );

function custom_wc_checkout_fields( $fields ) {

    // Remove Label text
    $fields['billing']['billing_first_name']['label'] = 'First Name';


    return $fields;
}

如何删除错误消息中作为前缀的“Billing”?

最佳答案

使用woocommerce_add_{$notice_type}过滤器。

例如

function customize_wc_errors( $error ) {
    if ( strpos( $error, 'Billing ' ) !== false ) {
        $error = str_replace("Billing ", "", $error);
    }
    return $error;
}
add_filter( 'woocommerce_add_error', 'customize_wc_errors' );

关于php - Woocommerce - 从错误消息中删除 'Billing' 字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40038028/

相关文章:

php - fatal error get_label() woocommerce 运输

php - 数据库统计

wordpress - 如何在 wordpress 上使用 qtranslate 翻译我的导航菜单链接?

mysql - ORDER BY 子句的表达式 #1 不在 GROUP BY 子句中并且包含非聚合列

c# - 添加具有多个属性的产品变体

php - 基于购物车商品数量的 WooCommerce 运费

php - 自定义表单日期和时间选择中的 Joomla 2.5 日历字段类型

php - 获取 Mysql $Row 和查询

php - FFMPEG : Add a fixed size image on a video, 不管视频的宽高(分辨率)

Mysql 查询 3 个表和用户元