简体   繁体   中英

How to set value for woocommerce custom fields?

I am using the following code in functions.php file. It's generating placeholder correctly. but value is not coming. I have used

$args['defaultval'] == "Value"; and $args['default'] == "Value";

But Nothing worked. Help me out this

 add_filter('woocommerce_form_field_args', 'custom_form_field_args', 10, 3);

    function custom_form_field_args($args, $key, $value) {
        if ($args['label'] == "t_size") { 
            $args['defaultval'] == "Value";
            $args['placeholder']="Place";
        }
        return $args;
    }

Use default instead of defaultval

Look here , this are the deafault args:

$defaults = array(
    'type'              => 'text',
    'label'             => '',
    'description'       => '',
    'placeholder'       => '',
    'maxlength'         => false,
    'required'          => false,
    'autocomplete'      => false,
    'id'                => $key,
    'class'             => array(),
    'label_class'       => array(),
    'input_class'       => array(),
    'return'            => false,
    'options'           => array(),
    'custom_attributes' => array(),
    'validate'          => array(),
    'default'           => '',
);

And here it will be used:

if ( is_null( $value ) ) {
    $value = $args['default'];
}

If $args['default'] not used, then the condition if ( is_null( $value ) ) isn't true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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