【问题标题】:WooCommerce: Add additional form field attributes to WC Vendors ProWooCommerce:向 WC Vendors Pro 添加其他表单字段属性
【发布时间】:2021-05-21 18:37:32
【问题描述】:

如果我在我的问题中使用了一些错误的术语,我们深表歉意。我是自学成才,还在学习。下面的代码是表单模板的一部分。我想为数组添加一些额外的属性。

我想知道如何在不清除模板现有属性的情况下做到这一点?

我想在我的子主题的 functions.php 文件中保留附加属性。

以下是我要修改的相关插件功能:

/**
 *  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' ),
                ),
            )
        )
    );
}

这是我想补充的:

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

【问题讨论】:

    标签: php arrays wordpress woocommerce field


    【解决方案1】:

    由于有过滤钩,请尝试以下操作:

    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);
    }
    

    代码进入活动子主题(或活动主题)的functions.php 文件中。它应该可以工作。

    【讨论】:

    • 这成功了!谢谢你,谢谢你,谢谢你!!!我刚刚通过 PayPal 向您发送了一些 $$$。
    猜你喜欢
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多