首页 > 解决方案 > 在 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&nbsp;<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&nbsp;<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; ?>

标签: phpwordpresswoocommerce

解决方案


您应该使用以下方法挂钩这些字段:

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.


推荐阅读