0

I've been battling with this one in Woocommerce a while now. I have set up the following function to fire off when the customer pays. As I have added a some custom fields, I want to add them to the order meta value to later get that information:

add_action( 'woocommerce_checkout_update_order_meta', 'cesaa_saved_custom_fields', 10, 2 );
function cesaa_saved_custom_fields( $order_id, $post_values ) {
    if ( !empty( $_POST['cesaa_member_id'] ) ) {
        $result = update_post_meta( $order_id, 'cesaa_member_id', sanitize_text_field( $_POST['cesaa_member_id'] ) );
    }
}

I've been debugging the function and it fires. The value $_POST['cesaa_member_id']is set but the update_post_meta fails because both $order_id, $post_values are always uninitialised.

Any clues on why this might be happening or what I could do to be able to debug this further?

Thanks!

0

So the code is fine. It must've been the way I was testing the checkout procedure that messed things up.

It worked after opening an incognito window and started the process from scratch...god these things are temperamental!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.