简体   繁体   English

WooCommerce:向 WC Vendors Pro 添加额外的表单字段属性

[英]WooCommerce: Add additional form field attributes to WC Vendors Pro

Apologies if I use some of the wrong terminology in my question.如果我在我的问题中使用了一些错误的术语,我深表歉意。 I am self-taught and still learning.我是自学成才,还在学习。 The code below is part of a form template.下面的代码是表单模板的一部分。 I would like to add some additional attributes to the array.我想为数组添加一些额外的属性。

I am wondering how I can do that without clearing the existing attributes of the template?我想知道如何在不清除模板的现有属性的情况下做到这一点?

I'd like to keep the additional attributes on my child theme's functions.php file.我想在我的子主题的 functions.php 文件中保留其他属性。

Here is the related plugin function that I would like to alter:这是我想更改的相关插件 function:

/**
 *  Output product title
 *
 * @since    1.0.0
 *
 * @param     int $post_id post_id for this meta if any
 */
public static function title( $post_id, $product_title ) {

    WCVendors_Pro_Form_Helper::input(
        apply_filters(
            'wcv_product_title',
            array(
                'post_id'           => $post_id,
                'id'                => 'post_title',
                'label'             => __( 'Product name', 'wcvendors-pro' ),
                'value'             => $product_title,
                'custom_attributes' => array(
                    'required'                   => '',
                    'data-parsley-maxlength'     => '100',
                    'data-parsley-error-message' => __( 'Product name is required or too long.', 'wcvendors-pro' ),
                ),
            )
        )
    );
}

Here is what I would like to add:这是我想补充的:

'placeholder' => __( 'Here is some placeholder text', 'wcvendors-pro' ),
'desc_tip'    => 'true',
'description' => __( 'Here is some description text.', 'wcvendors-pro' ),

Try the following as there is a filter hook:尝试以下操作,因为有一个过滤器挂钩:

add_filter( 'wcv_product_title', 'customize_wcv_form_field' );
function customize_wcv_form_field( $args ) {
    $more_args = array(
        'placeholder' => __( 'Here is some placeholder text', 'wcvendors-pro' ),
        'desc_tip'    => 'true',
        'description' => __( 'Here is some description text.', 'wcvendors-pro' ),
    );
    return array_merge( $args, $more_args);
}

Code goes in functions.php file of the active child theme (or active theme).代码进入活动子主题(或活动主题)的functions.php文件。 It should work.它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM