Is there a way to add multiple parameters when using woocommerce_checkout_order_created?

I noticed that when I try to add multiple params to woocommerce_checkout_order_created I get an internal server error on checkout when I try to pay and complete the transaction. Not sure why. My working code looks like this:

//----- add ecomm custom fields on placed order ----->>
add_action('woocommerce_checkout_order_created', 'add_custom_field_on_placed_order');
function add_custom_field_on_placed_order($order_id)
{
    $center_id = get_user_meta(get_current_user_id(), $key = 'location_id', $single = false);
    $guest_id = get_user_meta(get_current_user_id(), $key = 'visitor_id', $single = false);

    update_post_meta($order_id->get_id(), 'location_id', $location_id);
    update_post_meta($order_id->get_id(), 'visitor_id', $visitor_id);
}
//----- /add ecomm custom fields on placed order ----->>

but if I try to use

//----- add ecomm custom fields on placed order ----->>
add_action('woocommerce_checkout_order_created', 'add_custom_field_on_placed_order', 10, 2);
function add_custom_field_on_placed_order($order_id, $my_var)
{
    $center_id = get_user_meta(get_current_user_id(), $key = 'location_id', $single = false);
    $guest_id = get_user_meta(get_current_user_id(), $key = 'visitor_id', $single = false);

    update_post_meta($order_id->get_id(), 'location_id', $location_id);
    update_post_meta($order_id->get_id(), 'visitor_id', $visitor_id);
    update_post_meta($order_id->get_id(), 'something_else', $my_var);
}
//----- /add ecomm custom fields on placed order ----->>

I get an internal server err. Not sure why. Any ideas anyone?



Read more here: https://stackoverflow.com/questions/65745812/is-there-a-way-to-add-multiple-parameters-when-using-woocommerce-checkout-order

Content Attribution

This content was originally published by simlpymarkb at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: