Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created June 3, 2015 03:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillBrubaker/4d9f1cd122513e9eb0bc to your computer and use it in GitHub Desktop.
Save WillBrubaker/4d9f1cd122513e9eb0bc to your computer and use it in GitHub Desktop.
Restrict WooCommerce order notes field to a number of characters
add_filter( 'woocommerce_checkout_fields', 'filter_checkout_fields' );
function filter_checkout_fields( $fields ) {
$fields['order']['order_comments']['maxlength'] = 200;
return $fields;
}
@redmundial-uriel
Copy link

Hi,

I've tried this and didn't work in my WooCommerce installation (using version 3.6.5 and WordPress 5.2.2).

Any suggestions?

@WillBrubaker
Copy link
Author

Seems you probably have some troubleshooting to do. Here is where the filter is called in WooCommerce 3.6.5 https://github.com/woocommerce/woocommerce/blob/3.6.5/includes/class-wc-checkout.php#L265

@yoske25
Copy link

yoske25 commented Dec 19, 2019

Seems you probably have some troubleshooting to do. Here is where the filter is called in WooCommerce 3.6.5 https://github.com/woocommerce/woocommerce/blob/3.6.5/includes/class-wc-checkout.php#L265

Do you mind sharing the code we should use?

@WillBrubaker
Copy link
Author

@yoske25 exactly as written above:

see screen shot
https://d.pr/i/tywSOX

@TheRadicalDreamer
Copy link

It still does not work.

I am not able to get the order comments

image

Maybe the comments should be get by another hook?

@WillBrubaker
Copy link
Author

see screen shot

@TheRadicalDreamer
Copy link

becuase i have a pugin that modifies the checkout as well, my modifications did not display, but when i deactivated the plugin it worked ! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment