Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i make custom field value required ( compulsory ) in woocommerce product page when adding product

I have added custom text box field in my add product page in woocommerce. Now i want to make it required (compulsory). I tried it by passing argument "required"=>true. but it is not working. Please see below code

woocommerce_wp_text_input(
  array(
    'id' => 'special_price',
    'label' => __( 'Wholesaler Price *', 'woocommerce' ),
    'placeholder' => '',
    'desc_tip' => 'true',
    'required' => 'true',
    'description' => __( 'Enter wholesaler price here.', 'woocommerce' )
  )
);

but it is not making textbox compulsory. Please can anyone tell how can i do this?

like image 788
Vidhi Avatar asked May 23 '14 05:05

Vidhi


1 Answers

For the required HTML5 attribute and other custom attributes woocommerce_wp_text_input() function has custom_attributes option.

woocommerce_wp_text_input(
  array(
    'id' => 'special_price',
    'label' => __( 'Wholesaler Price *', 'woocommerce' ),
    'placeholder' => '',
    'desc_tip' => 'true',
    'custom_attributes' => array( 'required' => 'required' ),
    'description' => __( 'Enter wholesaler price here.', 'woocommerce' )
  )
);
like image 93
Danijel Avatar answered Oct 31 '22 15:10

Danijel