I want to add a default order comment (or pre populate the order_comments
field) if the cart total is over 25 euros.
I already found this post about it: Add a custom order note programmatically in Woocommerce admin order edit pages
I almost got it working:
add_filter( 'woocommerce_checkout_fields' , 'set_default_order_comment' );
function set_default_order_comment( $order, $fields ) {
// Targeting My account section
if ( $order->get_total() > 25 ) {
$fields['order']['order_comments']['default'] = 'Custom note!!';
}
return $fields;
}
At least, I think this should be it, but not quite right yet. I got this error:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function
How can create a simple function that checks the total amount in cart and if it is over 25 euro automaticly add an default order comment to the order?