0

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;
    }
1
  • you want to add custom fields ? (i.e. product, checkout, etc..) Commented Jan 2, 2017 at 12:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.