php - 在 WooCommerce 产品评论专业版中编辑评论评论字段
问题描述
我在我的网站上使用 WooCommerce Product Review Pro,并且喜欢更改名称和电子邮件字段。
详见附件:
谁能告诉我如何更改结构(使字段彼此落后)并添加占位符。
这就是这些字段在前端的样子:
<p class="form-row validate-required" id="review_author_field" data-priority="" style="display: block;">
<label for="review_author" class="">Name <abbr class="required" title="erforderlich">*</abbr></label>
<span class="woocommerce-input-wrapper">
<input type="text" class="input-text " name="author" id="review_author" placeholder="" value="">
</span>
</p>
<p class="form-row validate-required" id="review_email_field" data-priority="" style="display: block;">
<label for="review_email" class="">E-Mail <abbr class="required" title="erforderlich">*</abbr></label>
<span class="woocommerce-input-wrapper">
<input type="text" class="input-text " name="email" id="review_email" placeholder="" value="">
</span>
</p>
更新:此代码来自插件的模板文件
<?php if ( ! is_user_logged_in() && get_option( 'require_name_email' ) && ! get_option( 'comment_registration' ) ) : ?>
<?php if ( ! isset( $fields['author'] ) ) : ?>
<?php $fields['author'] = array( 'label' => __( 'Name', 'woocommerce-product-reviews-pro' ), 'required' => true ); ?>
<?php endif; ?>
<?php if ( ! isset( $fields['email'] ) ) : ?>
<?php $fields['email'] = array( 'label' => __( 'E-Mail', 'woocommerce-product-reviews-pro' ), 'required' => true ); ?>
<?php endif; ?>
<?php endif; ?>
解决方案
您应该使用以下方法挂钩这些字段:
add_filter( 'woocommerce_checkout_fields', 'change_checkout_fields_order' );
然后更改您要更改的字段的优先级:
function change_checkout_fields_order( $fields ) {
$fields['billing']['author']['priority'] = 4;
return $fields ;
}
请注意,此处选择的密钥可能与您的情况不同。如果你不确定你需要什么密钥,你总是可以先print_r()
看看$fields
.
推荐阅读
- java - 从日期转换为日期时间时如何删除时区
- python - 将两个多项式相乘的函数给出错误的结果
- javascript - 使用 Mapbox 读取本地 geojson 文件
- c# - 展开时字段名称冲突 (_id)
- tomcat - 我可以使用我的域证书启动 Tomcat 吗?
- scala - 如何在 spark scala 中将 Array[Any] 转换为 Long 数据类型以将数据存储在 scala 模型对象中
- python - 在 python 中创建模块 - 导入如何工作
- javascript - 使用箭头函数和类 get | 减少定义类常量的代码
- javascript - 使用查询参数向用户传递消息有什么问题吗?
- python - keras,两个张量列表的 MSE