【发布时间】:2016-10-14 08:03:19
【问题描述】:
在结帐错误中使用 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”?
【问题讨论】:
-
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { // 检查是否设置,如果未设置则添加错误。 if ( !$_POST['billing_first_name'] ) wc_add_notice( __( 'First Name is required' ), 'error' ); }
-
漂亮!这使我能够为特定字段添加另一个错误消息。如何隐藏原始错误消息?
标签: php wordpress woocommerce