1
votes

I use the Admin Order Page of WooCommerce to book certain products in a box office.

I want to make certain customer data required fields. (Like first_name,last_name,email etc.)

That the order can only be processed (saved) with this data entered in the billing information field.

I haven't found any solution on the internet that makes the fields in the admin panel required. Only found solutions for the frontend.

Any ideas?

1
I think you need to either alter the code of the plugin for this which is not a good thing if you want to keep updating the plugin or you must try to find a way to hook in admin code. Or just add required to the input fields with javascript or jquery and try this approach? Notice that this is only client side validation. But an easy solution. - Lars Mertens
@MrWeix did you check my answer? - Reigel

1 Answers

2
votes

this will prevent "Save order" button from firing if first_name is empty in the billing section.

add_filter('woocommerce_admin_billing_fields', 'woocommerce_require_admin_billing_fields');
function woocommerce_require_admin_billing_fields( $fields ){
    $fields['first_name']['custom_attributes'] = array( 'required' => 'required' );
    // $fields['last_name']['custom_attributes'] = array( 'required' => 'required' ); // for last_name
    return $fields;
}

but keep in mind that this prevention is only on client side and will not work on older browsers...
I can't find a way to stop post from saving on the server side.